Home > Back-end >  Alas, see more and more memory leaks, helpless.
Alas, see more and more memory leaks, helpless.

Time:10-11

Before always thought that is your own program memory leaks in great quantities, cause the program while it runs after many times of test found not his problem,
C.e xe inject b.d ll a.e xe inside
A.e xe itself has a growing problem in the operation of the memory,
The problem is not I consider
Then I began to seriously study b.d ll memory leak problem
Found in I create threads with memory leaks in the form I create run after generics also has a memory leak, I use a number of ways, always can't correct release, really helpless, a total of more than 20 generic list
 
If the list. Count<> 0 then
The begin

List. The clear;
end;
If Assigned (list) then FreeAndNil (list);
//some can release some cannot release cannot be released ahead of the strange, cause the failure of behind the release of all,
Thread on the inside also has use generic list
Call a process the data inside the clear first and then to add, add after, after use, to call process, this constant cycle,
There is a lot of data at the end of the thread to release,
Early know use generics is risky, thought wrote some of the Delphi program can feel it, but the risk really let me a headache
In the BBS post to find the answer to many don't understand why don't use up,
Feeling is right, but found or wrong after the execution, some compile cannot pass, feeling really good trouble ah,
Is still the old question, and the release of the generic list how to correct,,,

CodePudding user response:

Ha ha, or you,
I think this problem and generic, and List the container class relations is not big,
You still don't feel the object lifecycle management,

I carefully looked at you on a post, give you two advice
1, if you are not familiar with Delphi memory allocation and release, suggest change structure to the class, so that create and release are safe,
2, change the TList to TObjectList, can automatically release object to you,

CodePudding user response:

reference 1st floor WZZWWZ response:
ha ha, or you,
I think this problem and generic, and List the container class relations is not big,
You still don't feel the object lifecycle management,

I carefully looked at you on a post, give you two advice
1, if you are not familiar with Delphi memory allocation and release, suggest change structure to the class, so that create and release are safe,
2, change the TList to TObjectList, can automatically give you release object,


Answer very clearly identified, praise a, it's a pity that this wonderful work, still one track-minded,

CodePudding user response:

refer to the second floor ddqqyy response:
Quote: refer to 1st floor WZZWWZ response:

Ha ha, or you,
I think this problem and generic, and List the container class relations is not big,
You still don't feel the object lifecycle management,

I carefully looked at you on a post, give you two advice
1, if you are not familiar with Delphi memory allocation and release, suggest change structure to the class, so that create and release are safe,
2, change the TList to TObjectList, can automatically give you release object,


Answer was very clear, like a, it's a pity that this wonderful work, still one track-minded,

Thank you,

To the building Lord, since there are other people in favor of change a train of thought for solving the practical problems you (is the actual problem, not academic problems), why don't you try it? Want to know, programming is used to solve the problem, and also there are many kinds of the methods to solve the problem,

CodePudding user response:

TList. Clear won't release the memory, add a need to release the memory in the List one by one,

CodePudding user response:

And you have to use the structure pointer, you see here
http://www.cnblogs.com/del/archive/2008/11/10/1330456.html
To structure pointer to apply for and free memory should use New/Dispose rather than GetMemory and FreeMemory