← Back to team overview

unity-dev team mailing list archive

Re: Fixing a memory leak

 

[1] http://bazaar.launchpad.net/~unity-team/nux/2.0/view/head:/NuxCore/ObjectPtr.h#L178

2012/2/8 Andrea Azzarone <azzaronea@xxxxxxxxx>:
> 2012/2/8 Sven <svenb.linux@xxxxxxxxx>:
>> Hey all,
>>
>> I'm currently trying to fix as much memory leaks as I can find (because
>> I find that the most annoying part about compiz+unity), but I'm
>> currently stuck probably because I don't have enough knowledge about
>> unity yet.
>>
>> I have a lot of valgrind warnings of the form
>>
>> ==1933== 494,144 (2,112 direct, 492,032 indirect) bytes in 12 blocks are
>> definitely lost in loss record 10,579 of 10,585
>> ==1933==    at 0x4C291C7: operator new(unsigned long) (in
>> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
>> ==1933==    by 0x21F15B29: nux::Trackable::operator new(unsigned long)
>> (in /usr/lib/libnux-core-2.0.so.0.200.0)
>> ==1933==    by 0x21C6D920:
>> nux::GpuDevice::CreateSystemCapableTexture(char const*, int) (in
>> /usr/lib/libnux-graphics-2.0.so.0.200.0)
>> ==1933==    by 0x22E93A9A: unity::Tooltip::UpdateTexture() (in
>> /usr/lib/compiz/libunityshell.so)
>> ==1933==    by 0x22E93C10: unity::Tooltip::PostLayoutManagement(long)
>> (in /usr/lib/compiz/libunityshell.so)
>> ==1933==    by 0x231B4945: nux::View::ComputeContentSize() (in
>> /usr/lib/libnux-2.0.so.0.200.0)
>> ==1933==    by 0x2320694E: nux::WindowThread::ComputeQueuedLayout() (in
>> /usr/lib/libnux-2.0.so.0.200.0)
>> ==1933==    by 0x23207B78:
>> nux::WindowThread::RenderInterfaceFromForeignCmd(nux::Rect*) (in
>> /usr/lib/libnux-2.0.so.0.200.0)
>> ==1933==    by 0x22DD58C6: unity::UnityScreen::paintDisplay(CompRegion
>> const&, GLMatrix const&, unsigned int) (in /usr/lib/compiz/libunityshell.so)
>> ==1933==    by 0x22DD5F7E: unity::UnityWindow::glDraw(GLMatrix const&,
>> GLFragment::Attrib&, CompRegion const&, unsigned int) (in
>> /usr/lib/compiz/libunityshell.so)
>> ==1933==    by 0x11B3F18A: GLWindow::glDraw(GLMatrix const&,
>> GLFragment::Attrib&, CompRegion const&, unsigned int) (in
>> /usr/lib/compiz/libopengl.so)
>> ==1933==    by 0x11B3F5BC: GLWindow::glPaint(GLWindowPaintAttrib const&,
>> GLMatrix const&, CompRegion const&, unsigned int) (in
>> /usr/lib/compiz/libopengl.so)
>>
>> so I started digging into this. This is most likely caused by calling
>> texture_from_cairo_graphics, which allocates a new texture. The old
>> texture isn't deleted. This could be done manually after calling the
>> texture_from_cairo_graphics function, or even inside of that function,
>> but I digged a bit deeper, and found that texture_from_cairo_graphics
>> writes to a nux::ObjectPtr<nux::BaseTexture>.
>>
>> Looking into that, I found the assignment operator, and now I'm
>> wondering if maybe the assignment operators should be something like
>>
>>        ObjectPtr<T> temp(other);
>>        Swap(temp);
>>        if (temp.ptr_)
>>            temp.ptr_->Unreference()
>>        return *this;
>
> temp is a local variable so when the function return its dtor [1] is called.
> The destructor provides to release the reference.
>
>>
>> This seems to be what other functions do after creating a new texture,
>> so I wonder if this would fix my memory leaks.
>>
>> Kind regards,
>>
>> Sven (sbte on irc and launchpad)
>>
>> --
>> Mailing list: https://launchpad.net/~unity-dev
>> Post to     : unity-dev@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~unity-dev
>> More help   : https://help.launchpad.net/ListHelp
>
>
>
> --
> Andrea Azzarone
> http://launchpad.net/~andyrock
> http://wiki.ubuntu.com/AndreaAzzarone



-- 
Andrea Azzarone
http://launchpad.net/~andyrock
http://wiki.ubuntu.com/AndreaAzzarone


Follow ups

References