BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Release vs Free

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Writing
View previous topic :: View next topic  
Author Message
Yorai Aminov (TeamB)
Guest





PostPosted: Sat Oct 11, 2003 3:58 am    Post subject: Re: Release vs Free Reply with quote



On Fri, 10 Oct 2003 20:04:26 -0700, Ross C. Williams
<Aadvocacytechnologies (AT) iname (DOT) com> wrote:

Quote:
I noticed that TForm actually has a release method that should be used instead
of free.

Release actually posts a message to the form. The form destructs
itself when processing that message. This makes Release a lot safer
when timing issues may be involved.

This is less of an issue with modal forms. Since modal forms are
usually destroyed after returning from ShowModal, the window handle
may no longer exist and no messages are waiting to be processed by
that window.

Generally speaking, you should call Release from your form's methods -
that it, always use [Self.]Release instead of [Self.]Free. It's not as
important with modal forms, but really can't hurt.

---
Yorai Aminov (TeamB)
http://develop.shorterpath.com/yorai
(TeamB cannot answer questions received via email.)

Back to top
Marc Rohloff
Guest





PostPosted: Sat Oct 11, 2003 1:01 pm    Post subject: Re: Release vs Free Reply with quote



On Fri, 10 Oct 2003 20:04:26 -0700, Ross C.
Williams<Aadvocacytechnologies (AT) iname (DOT) com> said ...
Quote:
I have a number of components where I have added a dialog form to edit the
properties at run time. I have used the format:

For the way you are using it I think free is the way to go. Release
should only be used when the form's instance is currently being
referenced. For example if you are in a form click event you can't call
'free' because there is a reference to the form somehwere on the call
stack and you would get AVs. This is when you use release.

Also be aware that release won't free the form immediately but only when
the event queue is next processed which may not be immediately.

Marc

Back to top
hk.barton
Guest





PostPosted: Sun Oct 12, 2003 12:55 pm    Post subject: Re: Release vs Free Reply with quote



is that like this? :
postmessage(self.handle,WM_QUIT,0,0)?


Back to top
Francesco Savastano
Guest





PostPosted: Mon Oct 13, 2003 9:47 am    Post subject: Re: Release vs Free Reply with quote

Quote:
Also be aware that release won't free the form immediately

Very Interesting, i didnt know of that. Thanx to share.
One more thing: what you exactly mean here: "when the event queue is next
processed"



Back to top
Fauschti
Guest





PostPosted: Mon Oct 13, 2003 3:56 pm    Post subject: Re: Release vs Free Reply with quote

I really hope the create is qued after the .release and therefore, the form
should be released, before the variable is used for another instance of the
form.

anyway, it is quite uncommon, to use .release in this case (try ... finally
....)

as in many of this free <--> release discussions before, i think it does not
really matter, if you cal .free or .release from another form / unit, but if
you want to free the form within it's own unit, you should use .release to
give the components that are controled by that form a chance to get
destroyed without complications.

regards,
Michael


Back to top
Rob Kennedy
Guest





PostPosted: Mon Oct 13, 2003 5:21 pm    Post subject: Re: Release vs Free Reply with quote

Ross C. Williams wrote:
Quote:
So what happens if I reassign the variable immediately and before the
form is actually destroyed?

As long as you don't *use* that variable and expect to get the previous
form instance, you'll be fine. Neither the Release method nor the
wm_Close handler that eventually gets called require a valid reference
in your MyProc routine; they always have a valid Self to use.

Quote:
Or, as is more likely, I call a procedure that creates and releases
the form and then immediately call it again.

That's completely safe.

--
Rob


Back to top
Marc Rohloff
Guest





PostPosted: Tue Oct 14, 2003 11:52 am    Post subject: Re: Release vs Free Reply with quote

On Sun, 12 Oct 2003 20:55:46 +0800, hk.barton<hekphi (AT) hotmail (DOT) com> said
....
Quote:
is that like this? :
postmessage(self.handle,WM_QUIT,0,0)?

It's similar just a different message

Marc

Back to top
Marc Rohloff
Guest





PostPosted: Tue Oct 14, 2003 11:53 am    Post subject: Re: Release vs Free Reply with quote

On Mon, 13 Oct 2003 11:47:01 +0200, Francesco
Savastano<francosava (AT) libero (DOT) it> said ...
Quote:
Also be aware that release won't free the form immediately

Very Interesting, i didnt know of that. Thanx to share.
One more thing: what you exactly mean here: "when the event queue is next
processed"

I mean that if your application goes into a loop for 20 minutes then the
form won't be freed for the next 20 minutes, just as the GUI won't update
because no messages are being processed. This is not usually an issue.

Marc

Back to top
Marc Rohloff
Guest





PostPosted: Tue Oct 14, 2003 11:56 am    Post subject: Re: Release vs Free Reply with quote

Quote:
Or, as is more likely, I call a procedure that creates and releases the form
and then immediately call it again.

i.e.

Myproc;
Myproc;

It will do what you expect since Release is sent to the actual form
instance and not to the referencing variable (of which there could be
many).

Just remember that your form will, for a short period of time, exist
twice in memory.

Marc

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Writing All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.