INFO: FreeResource Not Necessary to Free Resources in Win32

ID: Q193678

The information in this article applies to:

SUMMARY

FreeResource is an obsolete function. It is provided for backward compatibility with 16-bit Windows applications. FreeResource is not necessary for 32-bit Windows applications to free the resources loaded using LoadResource function.

MORE INFORMATION

The resources in an application (.exe/.dll) are always mapped to the address space of a process. LoadResource simply retrieves the address of the resource that is already in memory. LoadResource does not allocate any additional memory.

The resource obtained with LoadResource is automatically freed when the module that it was loaded from is unloaded. If the resource is in a .dll, freeing the .dll using FreeLibrary also frees the resource.

When a resource is loaded with functions like LoadIcon, LoadCursor, LoadBitmap, LoadImage, LoadMenu, or LoadAccelerators, separate memory is allocated for the resource. You may release this memory by calling one of the functions in the following table:

   Resource                 Release function
   ------------------------------------------------
   Accelerator Table        DestroyAcceleratorTable
   Bitmap                   DeleteObject
   Cursor                   DeleteCursor
   Icon                     DeleteIcon
   Menu                     DeleteMenu

The system automatically deletes these resources when the process that created them terminates. However, calling the appropriate function saves memory.

Additional query words:

Keywords          : kbResource kbSDKPlatform kbGrpUser 
Issue type        : kbinfo

Last Reviewed: October 8, 1998