User talk:ScratchMonkey

From KitwarePublic
Jump to navigationJump to search

Smart Pointers

I have a SmartPointer question for you (since you clearly know what is going on - thanks for adding to the tutorial!), but I'm not sure who you are! Can you send me your email address?

daviddoria 00:50, 18 February 2010 (UTC)

I am trying to use a smart pointer for a member variable in this example:

In the MouseInteractorStyle class, I have:

    void SetRenderWindow(vtkSmartPointer<vtkRenderWindow> renderWindow) {this->RenderWindow = renderWindow;}
    //void SetRenderWindow(vtkRenderWindow* renderWindow) {this->RenderWindow = renderWindow;}
    vtkSmartPointer<vtkRenderWindow> RenderWindow;
    //vtkRenderWindow* RenderWindow;

If I use the smart pointer lines above (uncommented), debug leaks produces lots of messages. If I used the commented lines (non-smart pointer), it works fine. My thought was that in main, I have a vtkSmartPointer<vtkRenderWindow>, so I should continue to pass it around and store it as a smart pointer instead of a normal pointer. Is that not the correct thing to do?

Please take a look and let me know what you think.

Thanks! daviddoria 02:00, 18 February 2010 (UTC)

The code looks correct, except that I'd pass the smart pointer by const reference. I suspect that won't fix the leak, though. I'll have to compile it later and see if I can figure out what's going wrong. ScratchMonkey 02:32, 18 February 2010 (UTC)
    void SetRenderWindow(const vtkSmartPointer<vtkRenderWindow>& renderWindow) {this->RenderWindow = renderWindow;}

Have you also built VTK with DEBUG_LEAKS_ON? It was my understanding that building VTK with that option (not the Button project) was the key to finding the leaks? It is still leaking for me - I'm going to update to the latest CVS and try again, but mine is only a week old.

daviddoria 00:37, 19 February 2010 (UTC)