Uploaded image for project: 'Smack'
  1. Smack
  2. SMACK-383

Allow the garbage collection of all object instances of a closed and unreferenced connection




      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 (SMACK-418).

      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


          Issue Links



              • Assignee:
                flow Florian Schmaus
                a-iv Alexander Ivanov
              • Votes:
                0 Vote for this issue
                4 Start watching this issue


                • Created: