[QuantumSTEP] Fixed severe memory leak bug in ARP
H. Nikolaus Schaller
hns at goldelico.com
Sun Jan 2 22:03:13 CET 2022
Hi,
after several testing sessions and adding more test rig to
the source code, I was able to find and fix a memory leak
that was known for a while but the reasons were not...
The leak manifested itself in such simple things that the
loginwindow application did eat up memory more and more
even if a LetuxOS device was not operated otherwise.
It was introduced some years ago and never satisfactorily
solved because I though that it is an AppKit issue.
Leakage was so much that the Linux kernel on a typical
512 MB RAM machine (e.g. GTA04) did kill the loginwindow
process after ca. 1 hour due to out of memory situation.
Long research did show that the ARP cache pool was the
reason. It turned out that an ARP retain & dealloc sequence
did push an ARP object with retainCount=0 and a new
allocWithZone did pop with retainCount=0. This made it
different from a really new allocation if there was no ARP
object in the cache or the cache was disabled.
Everything did run fine afterwards - until the code using
the ARP (e.g. NSString or NSLog) did call [pool release].
This did no longer dealloc the ARP and so it was not drained.
So more and more unemptied ARPs were sitting in memory.
This has been fixed by incrementing the refCount if
needed. And another safety guard is to check recCount
to be non-zero when release is called.
This may also help to find other bugs in other frameworks
or applications.
After fixing this the memory allocation is now very
stable as an optional call to __NSPrintAllocationCount()
in NSRunLoop can show.
Source code repo of mySTEP has been updated as well as
the prebuilt Debian packages. So please run apt-get update
and apt-get upgrade. And please report problems and crashes.
-- hns
More information about the QuantumSTEP
mailing list