Jump to content
  • Advertisement

Archived

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

CGameProgrammer

I can't delete a perfectly valid piece of memory!

This topic is 5920 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a block of memory, and it creates an error when I try to delete it (regardless of whether I use delete or free). But, oddly, it appears to be perfectly valid otherwise - I can edit its contents, and _msize returns the correct size. It''s an array of 312 words, and _msize returns 624, perfectly correct. What can cause this? If it matters, the array is an array of indices used eventually for glDrawElements. ~CGameProgrammer( );

Share this post


Link to post
Share on other sites
Advertisement
For one thing, there is no confusion. I use delete. I just tried free for debugging purposes.

As for the code, I can''t show it because it''s my entire project. The part of the code that the error occurs in won''t help any because the block of memory is allocated/deallocated elsewhere and it''s always worked perfectly fine before.

Basically, the problem is what I stated. The memory block is valid and can be read from, but it can''t be deleted. It also cannot be debugged. When that "Click Retry to debug" dialog box appears, clicking any of its buttons causes a new instance of the same message box to appear, ad infinitum. I have to use Ctrl+Alt+Del to close the application. But I did find out which part of the code caused the error, and I tested the block of memory and found out the correct size was reported with _msize.

~CGameProgrammer( );

Share this post


Link to post
Share on other sites
1) did you new [] the memory?
2) did you delete [], and not delete the memory (not the same thing)?
3) are you sure the delete is causing the error, and its not because you are trying to access the memory after its been deleted (set the pointer to 0 after delete)?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Are you creating the memory in a different thread or process? Memory created in a .DLL and then used in a different process can be tricky to delete correctly, as you need to make sure the pointer to the memory location is returned corretly.

It''s difficult to help you with this problem when the details about how the memory is allocated is so vague.

Share this post


Link to post
Share on other sites
Double deletion might also causes problems. Or r u deleting some pointers (or references) to an automatic variables acidentally??

Share this post


Link to post
Share on other sites
You are almost certainly invoking undefined behaviour along the way, most probably corrupting the heap. You might be over-writing array bounds somewhere, which can certainly cause what you are seeing.

Share this post


Link to post
Share on other sites
I agree with SabreMan. You are most likely corrupting the heap somewhere else and that will in many cases cause what you are describing. I have tried this once before in a larger project and it is a pain to find the error. Also, make sure you are always setting the pointer to zero after deleting it, which will ensure you are not double-deleting (calling delete on a null pointer will do nothing).

René

Share this post


Link to post
Share on other sites
quote:
Original post by Spartacus
Also, make sure you are always setting the pointer to zero after deleting it, which will ensure you are not double-deleting (calling delete on a null pointer will do nothing).

I''d be careful with offering this advice. If you don''t want or expect an object to be deleted twice, and you nullify a pointer to allow it, you are covering up the real problem. It''s usually only worth nullifying pointers where it enables functionality.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!