unity-dev team mailing list archive
-
unity-dev team
-
Mailing list archive
-
Message #00416
Fixing a memory leak
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;
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)
Follow ups