SA Bugzilla – Bug 5452
Many circular references
Last modified: 2010-07-13 03:44:53 UTC
The SpamAssassin libraries create many, many circular references. Unless you are very careful, this could lead to a memory leak. Example: Dumping a Mail::SpamAssassin object after a SpamAssassin run reveals about 233 lines of back-references. The circular references are used for two purposes as far as I can see: 1) a "main" backreference back to the main SpamAssassin object so plugins can reach back into it. 2) "performance" backreferences to save typing and time so you don't need to dereference 4 or 5 hashes and arrays to walk the data structure. (1) could be solved by passing the main SpamAssassin object around as an argument to methods and functions that need it. (2) might be solvable by limiting the scope of the performance backreferences to "my" variables. Fixing this will be an awful lot of work. Maybe we should wait for Perl to have a proper mark/sweep GC engine. :-)
There's no reason those links couldn't be weaken()'d - we now require perl 5.6 IIRC?
yep, perl 5.6.1 is our current minimum. I didn't realise we could safely weaken refs with that - can we?
http://search.cpan.org/~lukka/WeakRef-0.01/WeakRef.pm Says it arrived in 5.005_55 (i.e. perl 5.6.0).
http://www.twoshortplanks.com/modulecorelist/index.cgi?module=WeakRef&version=&submit=Lookup : 'Module WeakRef was never distributed with perl.' :(
(In reply to comment #4) > http://www.twoshortplanks.com/modulecorelist/index.cgi?module=WeakRef&version=&submit=Lookup > : 'Module WeakRef was never distributed with perl.' > > :( You don't want WeakRef, you want Scalar::Util. It didn't hit core perl until 5.8, though.
(In reply to comment #5) > You don't want WeakRef, you want Scalar::Util. > > It didn't hit core perl until 5.8, though. Is Perl 5.6.1 still minimum? If possible, I'd like to have the weaken() calls in a future release. Circular references are causing a huge memory leak for spamd that makes it necessary to restart our daemon every hour or so. Daniel
Created attachment 4787 [details] Devel::Leak::Object memory leaks on Debian5
Created attachment 4788 [details] Devel::Leak::Object memory leaks on Win32 Hmm no comments on this? :( I did some little testing with Devel::Leak on a Win32 and a Debian5 system. Both of them are showing similar issues in terms of memory leak (reports attached). Looks like the problem is more serious for Windows, so I had a look on the differences: Sources of leaks: Math::BigInt 1 NetAddr::IP 8 Win32::API 14 Win32::Registry 7 These are not occuring on unix boxes (what a suprise for the last ones) so it may be the cause of the huge leaks. I guess this is more of a problem of Win32 perl modules, than of SpamAssassin, is that right? Daniel