Freeonterminate thread Management class destroy release when releasing manually issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.