Fixed
Details
Assignee
Florian SchmausFlorian SchmausReporter
Alexander IvanovAlexander IvanovLabels
Ignite Forum URL
Components
Fix versions
Affects versions
Priority
Critical
Details
Details
Assignee
Florian Schmaus
Florian SchmausReporter
Alexander Ivanov
Alexander IvanovLabels
Ignite Forum URL
Components
Fix versions
Affects versions
Priority
Created June 6, 2012 at 9:00 AM
Updated October 28, 2020 at 1:28 PM
Resolved October 18, 2014 at 8:20 AM
All instances related to an closed and unreferenced connection must be able to get garbage collected. This often failed in the past, causing a memory leak. The problem was/is especially severe on Android with aSmack, where we have frequent reconnects, because of connectivity changes (GSM<->WiFi) and limited memory. The root cause remains unknown atm, it's even possible that this is caused by many bugs/design flaws in Smack.
Possible/Identified causes are:
Issues regarding memory leaks
The Managers need to be redesigned, similar to the way of the attached patch. We need to design a common way how managers are created that allows the garbage collection of all their resources.
The codebase contains some flawed/wrong approaches to fix this. For example PEPManager.java:156 tries it with finalize. But it's a function without effect, because if finalize() if ever called, the local inner class had been already gc'd (Post).
Suggested solution:
1. Managers must not have a public constructor, just a `getInstance(Connection)` method. (We may have to exclude SDM from this constraint, but hopefully not).
2. Managers may always be created even if their functionality is not used. They may no get enabled though.
3. Use WeakHashMap for instances
4. If a Connection instance is used by the manager, make it a weak reference
5. Since Managers may always created, they must come with a enable() and disable() method
An ideal candidate that acts as example Manager that follows the 'new' approach would be the EntityTime Manager ().
To sum up, we have
App → Connection: strong reference
static manager instances → Connection: weak reference
static manager instances → Manager: strong reference
Manager → Connection: weak reference