Hello,

I am dealing with a heapdump of VFS where I see a lot of WeakRefFileListener
and all of them have a empty WeakRef to no listener. While I think I found the
reason for that and fixed it on a dependent project, it still does not clean
up correctly. I think the reason is that it does not store the WeakRefListener
directly, but it stores a WeakReflistener of it. This will then immediatelly
result in a unreferencedreferent - so it never works (it surely does fix the 
leak :)

Gary, while cleaning up lint errors in fba04f3e5 you made a change, but I asume 
it was
only a mechanical replacement - or did you actually checkedif it is correct?


https://github.com/apache/commons-vfs/blob/dc9ad7677a020b2d4c571f7dcc858cdbae2bb538/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/WeakRefFileListener.java#L41

Cleaned up code:
public static void installListener(final FileObject file, final FileListener 
listener) {
    file.getFileSystem().addListener(file, new WeakRefFileListener(file, new 
WeakRefFileListener(file, listener)));
}

initial version:
final WeakRefFileListener weakListener = new WeakRefFileListener(file, 
listener);
file.getFileSystem().addListener(file, new WeakRefFileListener(file, 
weakListener));


but I think it should be only a single wrapper:

public static void installListener(final FileObject file, final FileListener 
listener) {
    file.getFileSystem().addListener(file, new WeakRefFileListener(file, 
listener));
}

There is a mention of VFS-143, but itintroduced the whole code with the double 
indirection
and it does not explain why it is needed.

What do you think, should we change it? 

I also wonder why no tests sees it (in factI try to add a test to reproduce 
what I think
shows its not working).

Gruss
Bernd

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to