E N D
Runtime Memory Management presented by:- Roshan Kumar Sahoo(210720100091) MCA sec-B Batch - 2021-23
TOPICS:- • STACK • HEAP • STACK VS HEAP • GARBAGE COLLECTION IN JAVA
STACK:- • Stack is a linear data structure which stores a collection of objects. • stack follows LIFO algorithm. • mainly the following three basic operations are performed in the stack: • Push: Adds an element to the top of the stack • Pop: Removes an element from the top of the stack. if stack is empty it returns an Underflow • Top: Returns the top element of stack • isEmpty: if stack is empty it rerturns true, else false
Limitations of stack:- • Stack can only remove the last item you added • This works perfectly for local variables, since they come and go as the execution enters and exits functions • But, it does not work well for the data whose lifecycle does not depend on individual functions • the memory heap allows you to add and remove data whenever you want
GARBAGE COLLECTION:- • Garbage means unreferenced objects • Garbage collection is a process of destroying the unreferenced objects • In java, garbage collection is performed automatically, thus providing better memory management • If heap is full, garbage collection starts from the older objects
What is object cloning? • The object cloning is a way to create an exact copy of an object. for this purpose, the clone() method of an object class is used to clone an object. the cloneable interface must be implemented by a class whose object clone to create.