Fix accounting of memory usage in image cache
authorlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 10 Sep 2010 23:00:26 +0000 (23:00 +0000)
committerlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 10 Sep 2010 23:00:26 +0000 (23:00 +0000)
commit633418257cef0b7d2cbd663cd167341e20567251
tree401964fe50ec9583788b9f20f7b61faeac588e89
parentc5eafd8a7a09e97bf73e6cef8ebe49107dc49a17
Fix accounting of memory usage in image cache
Memory usage was not accounted right because
cache->func.mem_size_get(ie) returns 0 when called after
cache->func.destructor(ie). Thus the total memory used, kept on
cache->usage, is never decremented in _evas_cache_image_remove_activ()

This implies that cache->usage will keep growing and eventually it will
overflow, becoming negative. So evas_cache_image_flush() will not do its
job because cache->limit (assumed to be positive) will not be less than
cache->usage anymore. So the total memory allocated will start to grow
and the limit won't be respected.

Strictly speaking, it's not a leak, since all the memory will be
eventually freed when evas shutdown is called, but the program might be
killed by over allocating memory. This is caught by valgrind with the
massif tool. The graphic below shows that in the end a huge memory amount
is allocated. This is the moment when cache->usage became negative.

MB
26.04^                                                                   #
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
| :::::::::::::::::@@:::::::::@:::@::::::@::::::::::::::::::::::::::#::::
| : ::: ::: ::: :::@ :: ::: : @:: @:: :::@: :: ::: : : :: :: : ::: :#::::
0 +----------------------------------------------------------------------->Gi
0                                                                   54.83

This patch is a one line fix, which swaps the calls to
_evas_cache_image_remove_activ() and cache->func.destructor() making
cache->limit to be respected.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@52149 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33
src/lib/cache/evas_cache_image.c