how does a constructor achieve memory management in java

Status
Not open for further replies.

rookie1010

Fully Optimized
Messages
2,069
Hello

I was trying to get to grips with Java, and i came across this statement that constructing objects has a responsibility of
memory management.
how does a constructor achieve memory management? in the context of constructors is memory management the same as memory initialisation
 
Memory management is handled by the Java Virtual Machine (JVM), not an object's constructor. The constructor has the job of constructing or intializing the object.
 
what is memory management anyway?

is it the assignment of RAM memory to a process, that would be a kernel level issue, correct?
 
is it the assignment of RAM memory to a process
In the context of this discussion, no. If you ever do any substantial C or C++ programming, you'll see that the programmer is responsible for memory management. With Java and C#, their respective runtime environments manage the memory for you. For instance, when you create a new object in Java, you don't have to worry about keeping track of a pointer and freeing the memory when you are finished. The JVM handles that (garbage collection). In a C++ program, on the other hand, you'll need to manually free the memory you allocated with each "new" statement by using the "delete" (or "free") key word. Because the JVM is in charge of the memory management, Java has no concept of pointers as far as the Java developer is concerned.
 
Status
Not open for further replies.
Back
Top Bottom