Win32 API resource allocation and release quick query)

Source: Internet
Author: User

Below is a clear document for the allocation of Win32 resources found in a browser, which simply translates a few texts. The
This document is of great help to prevent resource leaks.
========================================================== ==========================================================
Does the resource allocation function need to be cleared manually?
========================================================== ==========================================================

Accelerators loadaccelerators N/A No

Atoms globaladdatom globalfreeatom Yes

Bitmaps createbitmap deleteobject Yes *
Createbitmapindirect deleteobject Yes *
Createcompatiblebitmap deleteobject Yes *
Createdibitmap deleteobject Yes *
Creatediscardablebitmap deleteobject Yes *
Loadbitmap deleteobject Yes *

Brushes createbrushindirect deleteobject Yes
Createdibpatternbrush deleteobject Yes
Createhatchbrush deleteobject Yes
Createpatternbrush deleteobject Yes
Createsolidbrush deleteobject Yes

Carets createcaret destroycaret no #

Clipboard openclipboard closeclipboard Yes

Comms ports opencomm closecomm Yes

Cursor createcursor destroycursor Yes
Loadcursor N/A No

DC createdc deletedc Yes
Createcompatibledc deletedc Yes @
Getdc releasedc Yes
Getwindowdc releasedc Yes
Beginpaint endpaint Yes

Dialog Box createdialog destroywindow No
Createdialogindirect destroywindow No
Createdialogindirectparam destroywindow No
Createdialogparam destroywindow No
File openfile _ lclose No

fonts createfont deleteobject Yes
createfontindirect deleteobject Yes
addfontresource removefontresource Yes

GDI stock OBJ getstockobject N/A No &

Hook setwindowshook unhookwindowshook Yes

IC createic deletedc Yes

Icon createicon destroyicon Yes
Loadicon N/A No

Library loadlibrary freelibrary Yes

Memory allocdstocsalias freeselector Yes
Allocselector freeselector Yes
Globalalloc globalfree No
Globaldosalloc globaldosfr No
Globalfix globalunfix No
Globallock globalunlock No
Globalpagelock globalpageunlock No
Globalrealloc globalfree No
Globalwire globalunwire No
Localalloc localfree No
Locallock localunlock No
Localrealloc localfree No

Menu createmenu destroymenu no %
Createpopupmenu destroymenu no %
Loadmenu destroymenu no %
Loadmenuindirect destroymenu no %
Getsystemmenu N/A No

Metafile createmetafile deletemetafile Yes

Palette createpalette deleteobject Yes

Pen createpen deleteobject Yes
Createpenindirect deleteobject Yes

Regions createellipticrgn deleteobject Yes
Createellipticrgnindirect deleteobject Yes
Createpolygonrgn deleteobject Yes
Createpolypolygonrgn deleteobject Yes
Createrectrgn deleteobject Yes
Createrectrgnindirect deleteobject Yes
Createroundrectrgn deleteobject Yes

Resource allocresource freeresource No
Findresource N/A No
Loadresource freeresource No
Lockresource unlockresource No

 

Sound opensound closesound Yes

String loadstring N/A No

Thunk makeprocinstance freeprocinstance No

Timer settimer killtimer No

Window createwindow destroywindow No
Createmediawex destroywindow No

========================================================== ==========================================================
Notes:
* When a bitmap resource is released, it must be removed from the selected DC.
% When the menu loses focus and the window is no longer associated or appliedProgramThe occupied resources must be released at the end.
@ DC must be associated with (selected) bitmap to cancel contact before it is released
# The bitmap must be released if the bitmap is specified
& Call deleteobject does not destroy General stockobject (system-defined resources)
========================================================== ==========================================================

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.