Home > Software engineering >  After the new object not delete and then end the program can automatically release space?
After the new object not delete and then end the program can automatically release space?

Time:10-07

 template 
ALGraph : : ~ ALGraph ()
{
for(int i=0; i{
ArcNode * p=adjlist [I] firstedge;
ArcNode * pp;
While (NULL!=p)
{
Pp=p - & gt; next;
The delete p;
P=pp;
}
}
Cout<" Delete "& lt; }

Void main ()
{
Int a []=,1,2,3,4,5 {0};
ALGraph * g=new ALGraph (a, 5, 5);
}

The key code as above, no implement destructors, isn't this part of the memory leak?

CodePudding user response:

Memory is leaked, but at the same time, the end of the process of recycling the memory,
Memory leak problem is in the process of running you constantly have to apply for memory, for a long time after the operation, as a result of insufficient memory collapses,
Just a piece of memory, there is no change, does not affect the running for a long time, just system a few less,

CodePudding user response:

reference 1st floor houen_study response:
memory is leaked, but at the same time, the end of the process of recycling the memory,
Memory leak problem is in the process of running you constantly have to apply for memory, for a long time after the operation, as a result of insufficient memory collapses,
Is a block of memory, it has no change, does not affect the running for a long time, just system a few less,

Since recycling memory why didn't the destructor call?

CodePudding user response:

The
refer to the original poster xbox1994 response:
 template 
ALGraph : : ~ ALGraph ()
{
for(int i=0; i{
ArcNode * p=adjlist [I] firstedge;
ArcNode * pp;
While (NULL!=p)
{
Pp=p - & gt; next;
The delete p;
P=pp;
}
}
Cout<" Delete "& lt; }

Void main ()
{
Int a []=,1,2,3,4,5 {0};
ALGraph * g=new ALGraph (a, 5, 5);
}

The key code as above, no implement destructors, isn't this part of the memory leak?

ALGraph * g=new ALGraph (a, 5, 5);
Use the new application of the memory system is not active recovery, need to manually delete, or it will cause memory leaks

CodePudding user response:

The
reference 3 floor lis2012 response:
Quote: refer to the original poster xbox1994 response:

 template 
ALGraph : : ~ ALGraph ()
{
for(int i=0; i{
ArcNode * p=adjlist [I] firstedge;
ArcNode * pp;
While (NULL!=p)
{
Pp=p - & gt; next;
The delete p;
P=pp;
}
}
Cout<" Delete "& lt; }

Void main ()
{
Int a []=,1,2,3,4,5 {0};
ALGraph * g=new ALGraph (a, 5, 5);
}

The key code as above, no implement destructors, isn't this part of the memory leak?

ALGraph * g=new ALGraph (a, 5, 5);
Use the new application of the memory system is not active recovery, need to manually delete, or it will cause memory leaks

The end of the program that piece of memory leak or not be recycled?

CodePudding user response:

reference 4 floor xbox1994 response:
Quote: reference lis2012 reply: 3/f

The
Quote: refer to the original poster xbox1994 response:

 template 
ALGraph : : ~ ALGraph ()
{
for(int i=0; i{
ArcNode * p=adjlist [I] firstedge;
ArcNode * pp;
While (NULL!=p)
{
Pp=p - & gt; next;
The delete p;
P=pp;
}
}
Cout<" Delete "& lt; }

Void main ()
{
Int a []=,1,2,3,4,5 {0};
ALGraph * g=new ALGraph (a, 5, 5);
}

The key code as above, no implement destructors, isn't this part of the memory leak?

ALGraph * g=new ALGraph (a, 5, 5);
Use the new application of the memory system is not active recovery, need to manually delete, or it will cause memory leaks

The end of the program that piece of memory leak or not be recycled?

There is no

CodePudding user response:

reference 4 floor xbox1994 response:
Quote: reference lis2012 reply: 3/f

The
Quote: refer to the original poster xbox1994 response:

 template 
ALGraph : : ~ ALGraph ()
{
for(int i=0; i{
ArcNode * p=adjlist [I] firstedge;
ArcNode * pp;
While (NULL!=p)
{
Pp=p - & gt; next;
The delete p;
P=pp;
}
}
Cout<" Delete "& lt; }

Void main ()
{
Int a []=,1,2,3,4,5 {0};
ALGraph * g=new ALGraph (a, 5, 5);
}

The key code as above, no implement destructors, isn't this part of the memory leak?

ALGraph * g=new ALGraph (a, 5, 5);
Use the new application of the memory system is not active recovery, need to manually delete, or it will cause memory leaks

The end of the program that piece of memory leak or not be recycled?

The operating system will help you recycle the memory

CodePudding user response:

Is there,,,

CodePudding user response:

ALGraph * g=new ALGraph (a, 5, 5);
G not delete must leak

CodePudding user response:

refer to the eighth floor worldy response:
ALGraph * g=new ALGraph (a, 5, 5);
G not delete affirmation leak

The baidu encyclopedia says
Leakage of memory leak is also called "storage", using dynamic memory allocation function of dynamic open space, in unreleased after using, as a result, have occupied the memory unit, until the end of the program,
Program ended the memory unit has not been occupied, which is released?nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related