Posted by Fox on 2000-12-22
Language: MFC C++ Compiler: MSVC++ 6 In a class, I have a bitmap pointer: CBitmap *bmp; In that program I assign it like so: bmp = new CBitmap; I fill it up with bmp->CreateCompatableBitmap(...); bmp->CreateBitmapIndirect(...); etc.... Now when I'm done with it what do I delete? Do I use: DeleteObject(bmp); delete bmp; Which do I use? Will I be deleting memory twice if I use both? To me it makes sense to do both because first you must delete the object (the 'DeleteObject'), then the memory allocated for the object (the 'delete bmp')...but is that true? No matter which way I've done it, I haven't seen any errors....except that when I use both, menu titles (and other lables) of other windows sometimes turn big and bold. But I haven't noticed a memory leak when I've used only one...either one. So which way is correct? Or am I suppose to use: DeleteObject(*bmp); Oh, this does bring up something else: what's the best way to see if a memory leak is happening? In other words: How can I be sure that ALL memory allocated by my program is being safely freed up? How does one hunt down and kill a memory leak? Especially one that doesn't seem to be happening every time the program is run? I thought I was careful to delete everything....apparently I was wrong. Any help? Need more info? Need more clarification? Please reply...thanks.
Previous post | Next post | Timeline | Home