No, garbage collection still happens inside of synchronized
. Also, this
will already be prevent from being garbage collected because it is on the stack, so you aren't getting any help there either.
I'm not sure what you are doing, but I think maybe you really want to be using SoftReference
rather than WeakReference
. Objects that are only referenced by a WeakReference
may be collected as soon as all hard references are gone. Objects referenced only by a SoftReference
may be kept until the VM runs low on memory.