java2
Transcribed by TurboScribe.ai. Go Unlimited to remove this message.
Why Java? Part 2. In Java, we have something called as automated memory management.
Whenever a program is running, a process is created and the memory is allocated to that
process, right? So in that memory, heap area is very crucial. So managing that heap area is
very important because the size is limited and that depends on the operating system.
So in C, C++, we have dynamic memory allocation but does not have a concept of dynamic
memory deallocation. So the programmer has to take care of memory deallocation to the
objects whenever the objects are no longer required. So the programmer has to manage
well else the memory is occupied by the object so we cannot create new object because of
no spatial issue and this is called memory leak problem in C, C++.
While in Java, we don't have that problem. Why? Because in Java, the beauty is we have a
background process or a facility called garbage collector and while our program is running in
background, one more program is running in the background that is called garbage
collector. At a regular interval of time, this garbage collector will check the memory and if
there are any unused object, it will free up the memory.
So there is no problem of memory leak in Java. Second, in Java, we don't have a concept of
pointers because pointers have direct access to memory and which is unsafe but in Java, we
have something called as references which is closer to pointers but it is safe.
Transcribed by TurboScribe.ai. Go Unlimited to remove this message.