Huge memory leak issues.

Started by
19 comments, last by silverphyre673 18 years, 10 months ago
delete[] mesh;
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
Quote:Original post by Fruny
delete[] mesh;


Well, I fixed that particular issue, but I think that the Get/Set routines aren't causing the problem - I'm pretty sure its in the contructor and destructor, since removing anything about Get/Set TerrainCell didn't affect the programs performance - allocating 30,000 doubles (1 Mesh of size 100x100) didn't affect performance visibly, but after creating and, in theory, destroying around 17 of them, my system came to almost a halt, and that is where I wound up using up all the system resources. I'm 100% certain its the destructor's fault.
my siteGenius is 1% inspiration and 99% perspiration
Quote:Original post by Fruny
delete[] mesh;


You mean like this? Tried it, and it didn't change anything, unfortunately

Mesh::~Mesh(){    for ( unsigned int i = 0; i < MESH_HEIGHT; ++i )    {        delete[] mesh;    }    delete[] mesh;}
my siteGenius is 1% inspiration and 99% perspiration
OK, I can't find it either, nobody. Actually, thanks alot for the help, Fruny. I tried something interesting: increased the size of MESH_WIDTH and MESH_HEIGHT to 1000 (basically made the size of a Mesh ten times bigger). And guess what: it ran exactly the same as when it was 1/10th the size, petering out after 17 destructor calls. So I guess the destructor is working. And after 17 tries, it slows down considerably, but it doesn't stop. I think if I left it running long enough, it would eventually finish. Anyone ever experianced this?

[EDIT] nevermind - instead it crashed after creating two Meshes, as I would have expected if the Mesh wasn't being created - having 1,000,000 must be no fun for the computer. I think I accidentally didn't do a full build, just compiled the wrong files. Any help, guys?
my siteGenius is 1% inspiration and 99% perspiration
What line of code is it crashing on? Have you tried debugging it?
Quote:Original post by silverphyre673
Quote:Original post by Fruny
delete[] mesh;


You mean like this? Tried it, and it didn't change anything, unfortunately

*** Source Snippet Removed ***

no, like this:

Mesh::~Mesh(){    for ( unsigned int i = 0; i < MESH_HEIGHT; ++i )    {        delete mesh; // delete single    }    delete[] mesh; // delete array}


why obfuscate things, I avoid nD dynamic arrays whenever I can
(it usually saves me time somewhere else *cough*debugging*cough*)
you can change it over when you're sure the code works.

struct MeshPointer {
Mesh *p;
};

MeshPointer *meshes;

for each M in meshes
delete M.p;
delete[] meshes;
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
Is there any particular reason why your storing pointers to TerrainCell instead of TerrainCell, which you have done in both cases with std::vector & C-style dynamic array.

Do you know std::vector separates allocation/deallocation & construction/destruction, so you can do things like allocate a chunk of uninitialized memory and then at a later time incrementally initialize each element (you can do this with C-style dynamic arrays but its low-level code)
Quote:Original post by silvermace
Quote:Original post by silverphyre673
Quote:Original post by Fruny
delete[] mesh;


You mean like this? Tried it, and it didn't change anything, unfortunately

*** Source Snippet Removed ***

no, like this:

*** Source Snippet Removed ***

why obfuscate things, I avoid nD dynamic arrays whenever I can
(it usually saves me time somewhere else *cough*debugging*cough*)
you can change it over when you're sure the code works.

struct MeshPointer {
Mesh *p;
};

MeshPointer *meshes;

for each M in meshes
delete M.p;
delete[] meshes;


I think I'll try this at home. I hate multidimentional arrays too :)
Not sure if it'll work, and I'm still not sure why the program is using all the resources, but I'll give it a shot.

Jingo: it's not crashing, just using all the system resources (memory).

snk_kid: I want to keep the memory off the stack to increase the amount of memory I can utilize. Tell me if this is false thinking.


my siteGenius is 1% inspiration and 99% perspiration
Quote:Original post by silverphyre673
snk_kid: I want to keep the memory off the stack to increase the amount of memory I can utilize. Tell me if this is false thinking.


It is. The vector already "keeps the memory off the stack"; the members of vector<T> look something like

int capacity; // how much storage space is allocatedint size; // how much of it actually corresponds to valid elements// possibly a couple other little things I forgotT* storage; // since it's variable, it would be kind of hard to put on the stack!

Really? That rules! I'm going to use vector even more than I already do. Problem solved.
my siteGenius is 1% inspiration and 99% perspiration

This topic is closed to new replies.

Advertisement