News for hackers. Stuff that matters.
Re:My favorite bug: segfaults in Java by kppullin on Saturday March 28, 2015 @10:33PM (#9283649)
I've faced similar issues in the .NET world. There is a built in method, `GC.KeepAlive()`, that does nothing other than keep the reference alive to the eyes of the garbage collector.

Raymond Chen explains it well here: http://blogs.msdn.com/b/oldnewthing/archive/2010/08/13/10049...

Re:My favorite bug: segfaults in Java by lamuerteflaca on Saturday March 28, 2015 @10:41PM (#9283661)
It completely defeats the whole point of a garbage collector if you have to resort to hacks like this. I understand why it is done. A lot easier to use the work around then to fix the root problem.

Unfortunatelly these types of bugs have a nasty way of showing up in other places where it can be even harder to debug. Long term these bugs need to be fixed otherwise your code will just be a ticking bomb. The worst part is when they combine with other bugs and they become even harder to debug.

Re:My favorite bug: segfaults in Java by dietrichepp on Saturday March 28, 2015 @10:53PM (#9283695)
I wouldn't say "completely defeats". The hacks are usually there only when you need to manage the lifetime of something that's not managed by the garbage collector. I've seen it used for mutexes, for example, to keep a mutex alive and locked.

You could say that the problem is that people abuse the garbage collector to manage something it shouldn't manage, or you could say that the problem is that garbage collectors are bad at managing anything that isn't memory. (I would lean towards the latter.)

Re:My favorite bug: segfaults in Java by nraynaud on Sunday March 29, 2015 @11:13AM (#9285077)
nope, when you have handles on resources outside managed memory, the GC is out and you need to have an acquire/release mechanism. This resource will probably have a bit of state visible on the managed side, so there will be some pinned memory.