Closed GoogleCodeExporter closed 9 years ago
Thanks for this patch.
Your implementation is the clean way to do a double-checked locking. It is
guaranteed to work on Java 5 and 6. However, not on Java 1.3 and 1.4. Which
Objenesis still support. However, it
1) Might work anyway
2) Be useless to keep supporting these old java implementations
3) Might be possible to support both world nicely
Out of curiosity, why are you synchronizing on clazz.getName().intern()? It's a
nice way to prevent using a transient?
Original comment by henri.tr...@gmail.com
on 7 Nov 2010 at 3:08
I wanted something unique out of the class to take a lock(which doesn't affect
callers getting instantiator for a different class, hence
class.getName().intern(). I could have used class, but didn't want to worry
about multi-classloader environments(re-loading of class while locked etc).
Using name avoids all that trouble.
Does it make sense to branch out for java 1.4/1.3 and not apply this patch
there? I don't know, its a little bit of effort, but since the patch is pretty
localized, it may make sense. Just a suggestion.
Original comment by singh.janmejay
on 9 Nov 2010 at 4:42
class.getName().intern() is a recipe for disaster of memory leaks
Original comment by dquint...@gmail.com
on 5 Jan 2011 at 12:36
well not exactly memory leaks, but memory exaustion
Original comment by dquint...@gmail.com
on 5 Jan 2011 at 12:38
It seems post java 1.2 it does get garbage-collected. Its a native call, and i
haven't checked how it works myself, but almost all pages i came across
indicate that interned strings are actually garbage collected(for instance
http://mindprod.com/jgloss/interned.html page talks about it).
Original comment by singh.janmejay
on 6 Jan 2011 at 2:51
Original comment by henri.tr...@gmail.com
on 23 Jan 2013 at 10:32
Here's a workaround I should have told way before.
You can do your own caching of the instances. For that, you should desactivate
the one from ObjenesisBase and just do your own.
You will still get a synchronized for any new class though. The next version of
Objenesis will not synchronize if the cache is disabled. Right now, the best
solution is to calling and instantiator used on your JVM directly instead of
using the strategy.
Original comment by henri.tr...@gmail.com
on 22 Jul 2013 at 11:20
It is now possible to implement its own cache and so remove the synchronization
in Objenesis.
Version 2.0 will be only Java 5 compatible and will be able to really fix this.
Original comment by henri.tr...@gmail.com
on 14 Aug 2013 at 11:45
Original comment by henri.tr...@gmail.com
on 14 Aug 2013 at 11:45
Original comment by henri.tr...@gmail.com
on 14 Aug 2013 at 11:51
Original issue reported on code.google.com by
singh.janmejay
on 4 Nov 2010 at 2:18Attachments: