[Digikam-devel] I'm back with questions - AutoCorrections tool memory usage and resource leaks
Matthias Welwarsky
matze at welwarsky.de
Thu Mar 4 08:41:52 GMT 2010
Hello all,
I've not been able to do much work on Digikam for quite some time but I still use it regularely and follow the development. Recently I have
noticed that the AutoCorrections tool seems to drive up memory consumption of digikam a lot and also seems to leak memory since I've
been getting strange crashes of Digikam recently that came from failed memory allocations during DImg construction.
I've looked into it and found two reasons. First is in the constructor of each of the correction filters:
NormalizeFilter::NormalizeFilter(DImg* orgImage, DImg* refImage, QObject* parent)
: DImgThreadedFilter(orgImage, parent, "NormalizeFilter")
{
m_refImage = refImage->copy();
initFilter();
}
Each filter does a deep copy of the reference image. For 12MP 16bit images this amounts to 100MB for each filter. The PreviewList has
one filter instance for each effect, so that's 5 times the memory of the image. Yet the filters don't change the reference image at all, so
detaching from the original data is not necessary. My current quick hack is to change DImg m_refImage to const DImg* m_pRefImage
and correct all the const'ness down the chain but it violates the ImageIface paradigm to never store the DImg* acquired through
ImageIface::getOriginalImage(). Since DImg copies are refcounted it should be possible by other means especially since all uses of the
refImage are const.
The first problem itself does not create a mem leak, it just largely exaggerates the memory usage. The second problem, which leads to
the mem leak is the undefined lifetime of the effect filters, especially those in the PreviewList.
The filter instances are never explicitely destroyed. They are either tied to the lifetime of the AutoCorrectionTool instance or the lifetime of
the PreviewList. But the PreviewList is created and tied to the _parent_ object of the AutoCorrectionTool, which is unfortunately the
ImagePlugin_Core instance, which has near infinite lifetime. I think you get the picture ;)
I hope I didn't annoy you with this long storytelling, but it teaches to be careful with the lifetime of objects, especially since memory
leaks like this don't show up in valgrind, due to the parent/child relationship the parent QObject will always hold a pointer to all its
children and valgrind will not notice the leak.
So, the patch for the PreviewList is trivial, but I would like your advice for fixing the image copying in the effect filters.
best regards,
matthias
More information about the Digikam-devel
mailing list