This question has been tossing my whole day. There is a thread management class that centrally manages all new threads, and thread unification identifies freeonterminate as True when it is created. Because some threads are infinite loops, these threads must be manually stopped and freed when the management class finally Destroy.
Start code:
Fallthread.items[i]. Fowner: = nil; No more messages to notify management class to delete records when released
Fallthread.items[i]. Terminate;
found that the FASTMM detection has a memory leak, think of the next because the thread is not over, but the main process is over, so it is normal to detect leaks. Thus added a sentence:
Fallthread.items[i]. Waitfor; Hopefully wait until the thread is released before continuing
Result error: Invalid handle!.... What situation?
Tracking source, until the implementation of the call Windows API ExitThread, can no longer follow, error!
After thinking, invalid handle, should be in the use of the handle when the handle does not exist, and finally focus on the Freeonterminate property, regardless of internal Delphi bugs, mostly related to thread release.
Final code:
Fallthread.items[i]. Fowner: = nil; No more messages to notify management class to delete records when released
Fallthread.items[i]. Freeonterminate: = False; // . Terminate;
Fallthread.items[i]. Free;
Pass! Toss!
Freeonterminate thread Management class destroy release when releasing manually issues