Results 1 to 7 of 7

Thread: does delphi require memory freeing?

  1. #1

    does delphi require memory freeing?

    As far as i heard you don't have to worry about freeing memory in Delphi, but i was wondering at what moment is the memory freed. Lets say i create a couple of forms when the program ir running and i close one, is the memory used by the closed form freed when it is closed or when the whole application closes?

  2. #2

    does delphi require memory freeing?

    No, memory is *not* automatically freed in Delphi (no garbage collection). What you are experiencing works only with VCL components/objects. Every VCL component derives from the TComponent class. The TComponent constructor takes another object as its "owner", to which it registers itself (you can see which objects are "owned" by a particular class by reading the ComponentCount and Components property). Whenever a VCL object is freed it automatically frees all the objects that it owns, and informs its owner that it has been freed. In this way you can create a form object with no owner, then create a bunch of components (buttons, labels, etc) with the form as their owner. When the form is freed it automatically frees all the components attached to it (though you shouldn't confuse Owner with Parent).

  3. #3

    does delphi require memory freeing?

    And to answer your question better: When forms are created by Delphi they are given the TApplication object as their owner. This means that they will be freed either when you manually free them or when the Application.Free method is called (which happens when the program shutsdown).

  4. #4

    does delphi require memory freeing?

    Thanks

  5. #5

    does delphi require memory freeing?

    So if I understand you correctly, when I create a component without specifying an owner (nil) then the object won't be freed from the memory if the application is closed?
    Do it by the book, but be the author!
    <br />
    <br />Visit the Lion Productions website at:
    <br />http://lionprod.f2o.org

  6. #6

    does delphi require memory freeing?

    Quote Originally Posted by TheLion
    So if I understand you correctly, when I create a component without specifying an owner (nil) then the object won't be freed from the memory if the application is closed?
    Yup.
    [size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]

  7. #7

    does delphi require memory freeing?

    :shock:

    That's nice to know...

    Thanks for the info!
    Do it by the book, but be the author!
    <br />
    <br />Visit the Lion Productions website at:
    <br />http://lionprod.f2o.org

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •