TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Monday 24 August 2020

Garbage Collection In C++ | Garbage Collection In C++ In Hindi

 

Garbage Collection In C++

Garbage collection is a form of automatic memory management. The

garbage collector or collector attempts to reclaim garbage, or memory

used by objects that will never be accessed or mutated again by the

application.

image of Garbage Collection In C++

Fig:Garbage Collection In C++



Advantages and Disadvantages of Manual Memory Management

Advantages of manual memory management are that the user would have complete control over both allocating and deallocating operations and also know when a new memory is allocated and when it is deallocated or released. But in the case of garbage collection, at the exact same instance after the usage the memory will not be released it will get released when it encounters it during the periodic operation.

Also in the case of manual memory management, the destructor will be called at the same moment when we call the ‘delete’ command. But in case of garbage collector that is not implemented.

There are a few issues associated with using manual memory management. Sometimes we might tend to double delete the memory occupied. When we delete the already deleted pointer or memory, there are chances that the pointer might be referencing some other data and can be in use.

Program:

#include<iostream.h>

#include<conio.h>

class A()

{

int x;

public:

A()

{

x=0;

++x;

}

};

void main()

{

for(int i=0;i<1000000;++i)

{

A *a=new A();

delete a;

}

std::cout<<”ding!”<<std::endl;

}

No comments:

Post a Comment