How do I prevent TMarker from memory leaking?

Hi,
Recently I valgrind’d a large package of mine and discovered that one of the main sources of leaks was TMarker.

Basically, I have a utility routine that that creates a TMarker (“new TMarker(xxx)”) and then Draw’s it. But never deletes it. Obviously, if it were to be deleted then the marker would no longer be on the canvas.

Do I have to implement a complex tracking to keep track of the TMarker instance until it is no longer needed? Or is there some other way to Draw it, and have it deleted when the TCanvas goes away on its own? Or… what other solutions have people used to take care of this?

Many thanks!

Cheers, Gordon.

Well it looks like a problem in your application. It is difficult to tell what solution you should adopt without knowing what you are doing. In particular, you are the one knowing when the markers are not needed anymore.

have you tried

marker->SetBit(kCanDelete);

?

[quote=“couet”]have you tried

marker->SetBit(kCanDelete);

?[/quote]

Thanks! I have total control of my application. I’m putting together a fairly complex plot, and I need to draw markers in several places. Acually, I’m making 100’s of these plots. Since the marker always goes along with some text (like a legend) I have a utility routine. It draws the marker and the text in the proper place on the canvas. It currently returns a void. To get this to work I’d have to track the new markers in a big vector or something, and then delete them after the canvas has been written out to a file and deleted itself.

I will try the CanDelete and see if that does anything, thanks!

[quote=“couet”]have you tried

marker->SetBit(kCanDelete);

?[/quote]

Just wanted to say thanks - valgrind confirmed that this isn’t a problem after adding this line!

Good !