thaliproject / Thali_CordovaPlugin

Thali p2p plugin
MIT License
226 stars 44 forks source link

ThaliCore: strong reference cycles throughout the code #1897

Closed enricogior closed 7 years ago

enricogior commented 7 years ago

ThaliCore has several strong reference cycles that prevent instances from being deallocated. Most of class instances in ThaliCore are keep alive forever: sessions, virtualsockets, tcpclients, tcplisteners and so on, are never deallocated. This is not only causing memory leaks, it may as well be the root cause of https://github.com/thaliproject/Thali_CordovaPlugin/issues/1891

The strong reference cycle is often occurring because of strong function references when passing callback handlers, the problem and a method to solve it is well described in this article: http://sveinhal.github.io/2016/03/16/retain-cycles-function-references/

enricogior commented 7 years ago

We believe we have fixed most, if not all, of them. Let's consider this issue resolved and we will open new issues for specific cases if more strong reference cycles will be found.