KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q199517: PRB: FreeResource Required for Locked Resources on Macintosh

Article: Q199517
Product(s): Microsoft C Compiler
Version(s): MACINTOSH:2.0,4.0,4.0b
Operating System(s): 
Keyword(s): kbHWMAC kbMFC kbVC200 kbVC400 kbGrpDSMFCATL kbNoUpdate
Last Modified: 11-MAR-2000

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual C++, Macintosh Cross-Development Addon, versions 2.0, 4.0, 4.0b 
-------------------------------------------------------------------------------

SYMPTOMS
========

Not calling FreeResource may cause Macintosh applications to leak memory.

CAUSE
=====

Resources on the Macintosh are fairly similar to Windows resources, but there
are a few differences.

In Win32 applications, resources do not have to be locked or freed. On Macintosh
platforms, however, calling LockResource does actually lock a memory block in
the heap. Not calling FreeResource causes that block to remain locked.

RESOLUTION
==========

To avoid memory leaks and heap fragmentation, FreeResource must be used on the
Macintosh when a resource loaded using LoadResource is no longer needed.

REFERENCES
==========

Macintosh Porting Guide: Resource Differences

Additional query words: FreeResource LockResource UnlockResource memory leak heap fragmentation

======================================================================
Keywords          : kbHWMAC kbMFC kbVC200 kbVC400 kbGrpDSMFCATL kbNoUpdate 
Technology        : kbVCsearch kbHWMAC kbOSMAC kbAudDeveloper kbVCXDev200Mac kbVCXDev400Mac kbVCXDev400bMac
Version           : MACINTOSH:2.0,4.0,4.0b
Issue type        : kbprb

=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.