Archived

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

new and delete

This topic is 6161 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''m using this memory tracker thing, it overrides new, delete, malloc etc. to find memory leaks. But it breaks when I try to delete a string made my strdup with free, saying "tried to deallocate memory not allocated with this manager" or something. So do I have to write my own strdup so that it uses the memory tracker? Also it complains if I do anything but the following combination: char *c = new char[n]; delete [] c; I thought it should be "delete c;" but it complains about that too. HEELPPPPP, I''m all confused about memory allocation now. Frank

Share this post


Link to post
Share on other sites
In the example you wrote out, the:
char *c = new char[n];
delete [] c;

Is correct. You would use delete c in the following case:
char *c = new char;
delete c;

I would advise writing your own strdup function, or just ignoring the error that it reports, if you can. Since in that case you should be fairly certain that it is working .



http://www.gdarchive.net/druidgames/

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Can you post a simple example of where it reports an error when you think it shouldn''t? That might help things out. Also, it could be complaining if you are trying to ''delete'' something that you created with ''malloc'', or ''free'' something created with ''new''.

Justin

Share this post


Link to post
Share on other sites
Are you using the memory log thing from glVelocity? If so, it should follow that message with an "attempting to recover gracefully" message that really ignores the first one.

Regards,
Jumpster

Share this post


Link to post
Share on other sites