Some experiences on resource release (Free/release/freeandnil) in Delphi

Source: Internet
Author: User

[Switch] Some experiences on resource release (Free/release/freeandnil) in Delphi

After studying free and release in Delphi during this period, we will summarize the following:
1. After the form. Free directly releases the resource, the ondestroy event is called, but the form pointer is not changed to nil.
2. Form. Release: Release the resource after the resource is no longer used. Also, the form pointer is not modified to nil. Therefore, it is best to use release to release the resource in destroy.
3. When releasing resources with local variables, you can use freeandnil () to release resources. This increases the efficiency and improves the memory utilization.
4. When operating the form, it is not enough to judge whether the form has been created by using assigned (form1) alone, because if the form is released through free/release, form1 points to an unknown address instead of nil. Therefore, you must use (not assigned (showform) and (not (showform is tform2 )) to determine whether the form has been created in the memory.
 

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.