Archived

This topic is now archived and is closed to further replies.

Phiro

Destroy vs Delete

Recommended Posts

Another question I''m not sure why, and in fact the actual cause may be something else entirely, but I have a small memory leak, eats up about 20k/sec. I change one thing, and it goes away. In a render function I have an object of CSurface I''m using to blt a bitmap to the screen. At the end of the function I clean up with: 20k/sec leak: g_pBitmap->Destroy(); With no apparent leak: delete g_pBitmap; Why isn''t Destroy good enough?

Share this post


Link to post
Share on other sites
i''m no DD guru but if you created g_pBitmap with the new operator then you should destroy it with the delete operator.
but if it''s a newly created object or pointer to an object it should work fine.

see how it was created, then check back, by then someone should tell you how it was works.

if this was no help so sorry.
just trying to understand it myself

Share this post


Link to post
Share on other sites
It sounds like g_pBitmap is never getting its reference count decreased to zero. Note that you should NEVER call delete on a pointer to a reference-counted object (unless you are the component API, of course). Objects do not expect to be deleted by anyone other than themselves, so their behavior is undefined. Check to see where else the reference count might be incremented, and make sure that any areas that do decrease it after they''re done.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
What exactly is g_pBitmap ? A ddsurface or a something else? I normally use..

if(ddSurface)
{
ddSurface->Release();
ddSurface = NULL;
}

I know you haven't specified which you are using, 7 or 8. so I am guessing, but I thought you called Release because that function removes it and decrements the reference counter.

Hope this is some help

[edited by - hammerstein_02 on October 3, 2002 3:58:42 AM]

Share this post


Link to post
Share on other sites