3 ms·
Space leaks are still possible in a managed language if you forget to nullify every reference to an old object, or if your garbage collector doesn't delete obje
by nitrogen 17y ago
Space leaks are still possible in a managed language if you forget to nullify every reference to an old object, or if your garbage collector doesn't delete objects that have a chain of circular references, and accessing a null reference still gives a NullPointerException. GC is nice, and real-time garbage collectors (such as rollendurchmesserzeitsammler) make managed languages useful in more situations, but they don't entirely free the programmer from thinking about memory management issues.
- mfairview 17y agoWith .Net there's also the issue with disposables of native resources. Also, if you're call takes a bit of time to complete, even automatic objects could get promoted up the generational chain unexpectedly. Take a look at the GC with MSoft's Singularity OS (bartok compiler). Looks promising but much farther down the road.
- vetinari 17y agoIf you don't nullify every reference, then the instance really should not be garbage collected, as it is not garbage yet. You should rather consider your application, where you are storing references and whether it is really needed (often better strategy is to make clone of the instance and treat it as disposable). Modern garbage collectors traverse the object graph and dispose everything, that is not in the graph - meaning, that closed chain of object with circular references is not a problem - they will get gc'ed. Accessing null reference does not give NullPointerException, ever. Dereferencing it does.
- eru 17y agoDepending on how I parse your first sentence, it's either true or false. And yes, in general, you can still leak memory in a GC'ed environment, when you don't think about what you need to keep in memory. Or if you use lazy evaluation (like in Haskell), thinks can go out of hand very easily.
- StrawberryFrog 17y agoSpace leaks are still possible in a managed language ... if your garbage collector doesn't delete objects that have a chain of circular references. That can be rephrased as "Space leaks are still possible in a managed language ... if your garbage collector is dysfunctional in a way that modern ones aren't". I don't see the relevance.