Reputation: 197
I want to know, why java (or gc-based languages like C#, GO) haven't any tools for direct memory management tools in addition to gc.
I am familiar with JLS and JVM spec, but I didn't find out any explanation of that.
It can boost performance (reducing amount of work for gc) and can decrease amount of used memory when developer can directly delete objects that he surely know aren't needed anymore.
I'm not familiar with python memory specification, but I know, that there are gc() method and keyword del for memory management.
P.S. I was googling for an hour, but I only find answers describing that I shouldn't care about deleting objects in memory management languages.
Upvotes: 5
Views: 251
Reputation: 147164
Java has always been security focussed, though never as important as ease of use. Non-garbage collected memory management is difficult to guarantee memory safety use, though see Rust for a good stab at it.
Good JVM implementations can stack-allocate "heap" objects in some time-critical circumstances. GC for short lived objects is incredibly fast anyway.
You can allocate memory outside of GC using the standard Java Class Library - java.nio.ByteBuffer.allocateDirect
. There isn't as yet, IIRC, a way to explicitly deallocate. That is does indeed require the GC to trace down all the references. The API will work well if you need fixed arrays of primitives that will last as long the process.
Upvotes: 4
Reputation: 14383
"It can boost performance"
how? explicitly free up memory takes time by itself. how is that better than letting the GC do its magic?
"decrease amount of used memory"
why should you care about the used memory? most modern applications employ "high water mark" strategy where they retain unused memory for future use.
"he surely know aren't needed anymore"
the cases where you have this certainty are becoming rare. any web application, even "hello world", deployed on modern servlet container/web server/web framework is too complex to let the developer decide on memory management.
Upvotes: 3