Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Memory Leak

Name: Anonymous 2008-12-06 19:46

So I'm writting an application in c++ using wxWidgets. to get some semblance of cross-platform compatability (it will eventually have to be ported to mac)

For one of the components, I have to display a sequence of bitmaps with as little delay as possible. So I load them into memory (~10mb) and store the pointers in a STL vector.

After this part quits and returns back to the main part of the application I call the delete operator on the vector in order to destroy the wxBitmap objects and dereference all the memory, but it doesn't, the docs say that the bitmap will get deleted if there are no more refernces to the bitmap and There arent (the only place the reference is stored is in the vector, it gets passed to the wxPanel doing the drawing, but I delete the panel before I delete the vector)

Hopefully someone can give me a hint in the right direction.

Name: OP 2008-12-07 16:15

>>16

It is a vector of pointers, I allocate the vector with

std::vector< wxBitmap *> images;

then I go through a zip archive and extract images from it.

bmp = new wxBitmap(*img); //where img is a pointer to the  extracted image

bmp_resized = new wxBitmap(resize(*bmp, x_max, y_max));
//Where resize is a method that returns a new resized wxBitmap
//after fucking around with its dimensions

images.push_back(bmp_resized);

delete bmp;
delete img;
// loop back to process the other images in the archive.


when I delete the vector I go through it with an iterator and call delete on every element. Then I clear the vector and delete the vector itself.

I realize this is a bit of newbie question, but this is the first time I've delt with wxWidgets (on my other projects I didnt work alone so I never touched interface design if I could help it)

I'm thinking that maybe if I change everything to work with actual objects instead of pointers I will get rid of some of the headache at the cost of some efficiency., but in this application timing is key. It's an experiment for some psychiatrists and they need to be able to control the amount of time an image is displayed to one microsecond.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List