-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CBLListener retaining CBL_RunLoopServer so both never get freed. #1921
Comments
From the graph, I could see the circular references between |
And I just found out the purple [!] indicate leaks. |
As a test I set the listener on CBLHTTPConnection.h to weak:
That improved things so now the CBL_RunLoopServer no longer exists after closing. But a couple of classes in the CouchbaseLiteListener are still hanging around. Namely That was just a test though to see what would happen. I'm sure you'll have a better fix. |
If I don't startup the listener, then the CouchbaseLite framework classes properly get deallocated when I close my file. |
Adding this code to remove the loggers in
|
Perhaps going a bit ballistic to try and resolve this issue, I've been doing more experimentation with cleaning up things: CBLSyncListener.m Changed
added these to
CBLManager.m added to
CBLHTTPConnection.h changed:
to:
So maybe overkill in some spots. But it seems to get the job done. |
This might not be correct for example if starting 2 replicators. Also if you don't enable |
Somehow I don't see the replicator leaks as you mentioned in #1921 (comment). Also it is a good idea to create a separate ticket for replicator leak. |
From #1921, the leak is caused by the circular references between CBLHTTPConnection and CBLHTTPListener. Making the listener property in CBLHTTPServer as a weak reference should fix the issue.
@brendand I did a minimum fix. I don't fix the Logger issue as the CBL_MYDDLogger is created once for the CBLHTTPListener class, and it will be created only when the |
I have a
TFDatabaseDocument
class that holds on to a CBLListener and a CBLManager instance.I create the
CBLListener
like this:When I close my
TFDatabaseDocument
class, I do these things in a stop method I call before the document is closed:I also stop the CBLManager and nil it out too, just to be sure.
I can confirm that
dealloc
is definitely being called when myTFDatabaseDocument
class closes and it's deallocated properly.However, when I use the memory graph debugger in Xcode, I see that the
CouchbaseLite CBL_RunLoopServer
and a bunch of classes inCouchbaseLiteListener
are still in memory.Here's what the memory graph debugger shows in Xcode 9:
I tested to see what happens when I don't instantiate a
CBLListener
and I find thatCouchbaseLite CBL_RunLoopServer
no longer appears in the Xcode 9 memory debugger when I release my class.So it seems to me that when you instantiate a listener, it's retaining the
CBL_RunLoopServer
even when you deallocate your class that holds the listener. And this prevents the listener from freeing up all of its resources and theCBL_RunLoopServer
.I've tested this both on macOS 10.13 and iOS 11. Same results on both.
Is there another way I should be trying to clear out the
CBLListener
?The text was updated successfully, but these errors were encountered: