Delphi2009 First Experience

Source: Internet
Author: User
Tags printf

I. Review of History

In C + +, objects can be created either on the stack or in the heap. Such as:

class CTestClass
{
public:
   CTestClass()
   {
     printf(“Create”);
   }
   void DoPrint() {}
   ~CTestClass()
   {
     printf(“destroy”);
   }
}

The following code creates a stack object

CTestClass test;
test.DoPrint();

Stack object lifecycle is managed by the background. When the method ends, the Stack object pops out of the stack, and the compiler automatically destroys the objects that are ejected from the stack.

The following code creates a heap object

CTestClass* test = new CTestClass();
test->DoPrint();

Heap objects are stored in the heap, the heap object lifecycle is not managed by the background, and the programmer must manually release the heap object, or it will cause a memory leak:

delete test;
test = NULL;

Pascal language supports object-oriented from OOP Pascal, i.e. OOP Pascal supports creating objects. As with OOP Pascal and C + +, you can also create stack objects and heap objects, respectively:

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.