Closed wsxyeah closed 5 years ago
I'm sorry for the implementation and thank you for your finding the issue. I released nv-websocket-client 2.7 that includes the fix for the issue just now. I hope it can solve the issue.
Thank you your reply.
But I got one question about the synchronization: when there is any iterator of mCopiedListeners
is in use(just like callOnFrame
method), in the meantime we call mCopiedListeners .clear()
, this may cause ConcurrentModificationException
, so it's not quite safe, right?
@TakahikoKawasaki how about using collections from java.util.concurrent
, i.e. CopyOnWriteArrayList in stead of rolling your own synchronisation?
Thank you for pointing it out. I'm thinking of fixing the code like below.
public void clearListeners()
{
synchronized (mListeners)
{
if (mListeners.size() == 0)
{
return;
}
mListeners.clear();
mCopiedListeners = null;
mSyncNeeded = true;
}
}
Do you have any concerns about this?
BTW, the reason nv-websocket-client does not use java.util.concurrent
is mainly because I was not familiar with the package when I started to implement nv-websocket-client. The reason I don't replace synchronization operations in nv-websocket-client with java.util.concurrent
is that I don't have time to maintain this library. I update this library only when a critical issue is reported and I estimate it can be easily fixed. Sorry for this inconvenience.
@TakahikoKawasaki If you don't mind I'll supply a PR.
@eku Thank you, but a problem is that I cannot spare enough time for review if a PR is big.
Released nv-websocket-client 2.8 which includes the fix I suggested above.
Even I called
ListenerManager.clearListeners
,ListenerManager.mCopiedListeners
still keeps strong references of my listener, which may cause memory leak.Should we clear
mCopiedListeners
at that time?