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

Pages: 1-4041-

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: Anonymous 2008-12-06 20:02

1. "Dereference" does not mean what you think it does.
2. You must have multiple wxBitmaps using the same data.
3. Don't use Sepples.
4. Why aren't you using garbage collection?

Name: Anonymous 2008-12-06 20:18

wxWidgets sucks. Sepples sucks. You don't know how to use either. You suck.

Name: Anonymous 2008-12-06 21:43

>>2
I am using garbage collection. Every thursday is garbage collection day. Garbage trucks are sent out by council on this day.

Name: Anonymous 2008-12-06 22:12

>>4
This is what Ctards actually believe.

Name: OP 2008-12-06 22:41

I don't have much of a choice, I'm being paid to write it in c++ and widgets. It wasn't my first choice in either case, but I'd take widgets over MFC or WIN32 any day.

Its not really a difficult question. I iterate through the vector with delete and no memory is freed. There is a massive 10 mb leak everytime I load the component. Granted its not as bad as firefox, but still a pain in the ass.

Name: Anonymous 2008-12-07 1:19

>>1,6
Same person.

Name: Sage 2008-12-07 1:37

There's a very large book for the bloated language of C++ you should consider reading before posting any further:

The C++ Programming Language "Special Edition"

Vectors
16.3 Pages 442-458

If you can't figure it out from there, guess you'll just have to post the code.

Name: Anonymous 2008-12-07 4:14

>>2
>4. Why aren't you using garbage collection?
Or maybe he should use Boost's smart pointers.

Name: Anonymous 2008-12-07 4:38

Or maybe he should be using MONADS.

Name: Anonymous 2008-12-07 4:41

>>6
>I'd take widgets over MFC or WIN32 any day.
This is true.

>>9
wxBitmap and wxImage internally reference-counted through copy and assignment construction so using boost::shared_pointer would be redundant.

My advice to OP is to make a debug build of the wxWidgets library and either instrument it with trace statements or step through in the debugger to see where each image ref-count is being incremented and decremented.

Name: Anonymous 2008-12-07 4:53

>>6
I iterate through the vector with delete and no memory is freed.

You realize ~vector deletes the vector's contents, right?

Anyway there are really only two possibilities here: you've discovered a huge bug in wxWidgets, or you're creating multiple wxBitmaps that use the same data.

Name: Anonymous 2008-12-07 4:57

The destructor of a vector doesn't automatically call delete on the pointers. It just deletes the pointers, but not what they point to. So before you delete the vector first delete each pointer in the vector.

Name: Anonymous 2008-12-07 5:25

KILL IT WITH PRINTF

Name: Anonymous 2008-12-07 6:12

>>13
It's not a vector of pointers, or at least it shouldn't be. It's a vector of wxBitmaps.

Name: Anonymous 2008-12-07 6:28

>>15
I'm confused about a couple things. First of all, how are you allocating the vector (stack, instance variable of class, via new... ???). Next, what is inside the vector, pointers or object instances? This entire operation reeks of amateur hour.

Name: Anonymous 2008-12-07 10:49

>>14
This

Name: Anonymous 2008-12-07 10:52

>>16
That

Name: Anonymous 2008-12-07 11:29

My anus is leaking memory.

Name: PROXY FAN 2008-12-07 12:52

>>19
Watch out. Moments before Haskell died, her anus was leaking memory everywhere.

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.

Name: Anonymous 2008-12-07 16:28

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.
This is on a magical 1000000Hz display, I suppose?

Name: OP 2008-12-07 16:43

>>22

Sorry, I meant millisecond.In any case using objects instead of pointers affected my timer precision when I was doing proof of concept tests. While I know that extreme precision is impossible I still need the data log at the end to say that the delay was exactly equal to what they specified.

Name: Anonymous 2008-12-07 16:48

>>23
Why are you using Sepples for a real-time system?

Name: Anonymous 2008-12-07 16:53

>>24
Because he doesn't know what a real-time system is.

Name: OP 2008-12-07 17:20

Not my choice... once again I didnt make these decisions. I'm paid to do what they want me to do. They tell me to write a bunch of code in c++, I do it. The motherfucker wants me to rewrite everything in java by next week to. but thats besides the point (At least I get paid again).


The word experiment is a bit strong for this, it basically involves showing pictures on screen and recording various data related to subject response.

Name: Anonymous 2008-12-07 17:29

>>21
I'm wondering about the potential of that resize method to leak something internally.  You could do worse than print out a statement of total memory allocated after each step of this and see where the chunk gets allocated that doesn't go away.

Anyways, a wxBitmap object is a comparatively cheap thing to copy around -- reference counting means that it doesn't copy the image data, just the pointer-to.

Name: Anonymous 2008-12-07 17:37

The debug version of your C runtime should be able to provide you with some sort of break-on-alloc-id capability, and be able to list the alloc IDs of leaked memory when the program exits. It might help.

Name: Anonymous 2008-12-07 17:55

Then I clear the vector and delete the vector itself.
What do you mean, you "delete the vector itself"? As in, you're using the delete operator on the vector? That isn't necessary, and I'm not surprised that you segfault if that's what you're doing.

Name: Anonymous 2008-12-07 19:11

>>21
std::vector< wxBitmap *>
boost::ptr_vector< wxBitmap >

Name: Anonymous 2008-12-07 19:24

>>30
Yeah, I recommend not using the boost library for something as trivial as this.

Name: Anonymous 2008-12-07 19:34

>>31
I recommend not using the STL for something as trivial as this.

What are you, daft?

Name: Anonymous 2008-12-07 20:55

>>32
Why pull in all of that template cruft when the standard library already has something sufficient? I'm talking about auto_ptr

Name: Anonymous 2008-12-07 20:55


             ~~~~~FILTHY SEPPLIST~~~~~

                      ______
                   .-"      "-.
                  /            \
 
                 |,  .-.  .-.  ,|
                 | )(__/  \__)( |
                 |/     /\     \|
                 (_     ^^     _)
                  \__|IIIIII|__/
                   | \IIIIII/ |
                   \          /
                    `--------`

         YOU DIED BECAUSE YOU ARE DISGUSTING,
           BUT THE CURSE ENDS NOT AT DEATH.

Name: Anonymous 2008-12-07 21:03

>>33
You can't put auto_ptrs in a C++ standard library container because its copy constructor doesn't have ``nice'' semantics.

Name: Anonymous 2008-12-07 21:29

>>33
Why pull in all of that template cruft
Because you're using a broken language. On modern machines what does it matter anyway? Also, >>35.

Name: Anonymous 2008-12-08 1:12

And adding 54 layers of template indirection and broken-bandaid-on-broken-language will really help a newbie debug a basic memory handling error.

Name: Anonymous 2008-12-08 9:10

>>37
It's not my fault that noobie chose (or was assigned) the final boss of programming languages. There's no reason he can't write it in something more reasonable -- there are wxWidgets bindings for practically everything.

Name: Anonymous 2009-09-17 20:23

Lain.

Name: Anonymous 2009-09-17 20:24

Lain.

Name: Anonymous 2009-09-17 20:25

Lain.

Name: Anonymous 2009-09-17 20:25

Lain.

Name: Anonymous 2009-09-17 20:26

Lain.

Name: Anonymous 2009-09-17 20:26

Lain.

Name: Anonymous 2009-09-17 20:27

Lain.

Name: Anonymous 2009-09-17 20:27

Lain.

Name: Anonymous 2009-09-17 20:28

Lain.

Name: Anonymous 2009-09-17 20:29

Lain.

Name: Anonymous 2009-09-17 20:29

Lain.

Name: Anonymous 2009-09-17 20:30

Lain.

Name: Anonymous 2009-09-17 20:30

Lain.

Name: Anonymous 2009-09-17 20:31

Lain.

Name: Anonymous 2009-09-17 20:31

Lain.

Name: Anonymous 2009-09-17 23:04

Lain.

Name: Anonymous 2009-09-17 23:04

Lain.

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