|
-
Oct 20th, 2008, 07:14 PM
#7
Memory Leak Prevention and Detection
The following listing is not all-inclusive
1. When using LoadImage API, you should not destroy anything you created if the LoadImage used the LR_Shared flag. Windows will destroy these when done with them.
2. When using CopyImage API, you do not have to destroy the original image you copied if you included the LR_CopyDeleteOrg flag with the call. That flag will destroy the original image for you.
3. When creating a region via the many region APIs, you must not destroy the region if you used SetWindowRgn with it. Windows will destroy it when done with it. In fact, you are not even supposed to reference that region handle again, ever.
4. I cannot think of any reason to destroy items contained in Visual Basic standard picture or standard font objects. Visual Basic does a real good job with these. However there is nothing wrong with setting the objects to Nothing or using LoadPicture(""), for images, before setting them to something else.
5. The GetStockObject API returns one of several permanent drawing objects. Do not destroy any returned by the API as they belong to the system.
6. If you use RegisterClass API to create a new window class, you may have also created a background brush for the class. If the class is successfully registered, the brush will be destroyed by windows when the class is eventually unregistered.
7. Some APIs may actually create objects that you don't need to be concerned with. For example the SelectClipRgn requires you to pass a region handle. It then copies the region and will destroy it when another region (actual or null) is selected into the DC or when the DC is destroyed. However, at some point in time, you must destroy the original region you passed to that API.
Last edited by LaVolpe; Oct 21st, 2008 at 09:51 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|