Delphi about resource Release (Free,relealse,freeandnil)

Source: Internet
Author: User

According to the daily programming experience, we can get some experience about the release of resources in Delphi.

If there is an object obj is a tobject type:

1 Obj.free The resource directly, the OnDestroy event is invoked, but the OBJ pointer value is not placed as nil.

2) Obj.release wait for resources to release resources after they are no longer in use, and also do not modify OBJ pointers to nil, so it is best to use release for resource deallocation in OnDestroy.

3 Local variables to release resources, you can consider using Freeandnil () to release resources, so the efficiency is higher, can improve the utilization of memory.

4 It is not enough to judge whether an object has been created simply by assigned (obj), because obj points to an unknown address instead of nil if the object is freed through free/release, so you need to use (not assigned (OBJ)) and ( Not (the OBJ is TObject) to determine if the object has been created in 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.