Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Repeated Release/Destroy


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Apr 18, 2018 4:07 PM Last Post By: Rudy Velthuis (... Threads: [ Previous | Next ]
William McDonald

Posts: 3
Registered: 10/2/08
Repeated Release/Destroy  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 29, 2015 12:24 PM
I have an application that occasionally throws an error because it is attempting to free an object that has already been freed. All of the forms have code in them that logs the creation and destruction of the form in the corresponding event. Looking at the log for the session that generated the error I see at the end that the OnDestroy event was executed three times in a row. The only time a form is released is when the user elects to move to a different form. There is no way that normal execution of the program could release a form without having created it first. And yet it happened. Has anyone seen this behavior?

The code to change forms is as follows:
procedure TFramePgHdr.Move(AFormClass: TIWAppFormClass; FormName: string);
begin
  if TIWAppForm(WebApplication.ActiveForm).Name = FormName then
    exit;
  // Release the current form
  // Note that Intraweb keeps track of which forms exist
  TIWAppForm(WebApplication.ActiveForm).Release;
  // Create the next form
  if TIWAppForm(WebApplication.FindFormByName(FormName)) <> nil then
       TIWAppForm(WebApplication.FindFormByName(FormName)).Show
  else
       AFormClass.Create(WebApplication).Show;
end;


The log for the session is as follows: (ActionValue of 1=form created, -1=form destroyed)
FORM ACTIONVALUE DATECR
TfrmLogin 1 7/27/2015 3:36 PM
TfrmChangeYard 1 7/27/2015 3:36 PM
TfrmLogin -1 7/27/2015 3:36 PM
TfrmViewYard 1 7/27/2015 3:36 PM
TfrmChangeYard -1 7/27/2015 3:36 PM
TfrmRackSmry 1 7/27/2015 3:36 PM
TfrmViewYard -1 7/27/2015 3:37 PM
TfrmViewYard 1 7/27/2015 3:37 PM
TfrmRackSmry -1 7/27/2015 3:37 PM
TfrmInventory 1 7/27/2015 3:37 PM
TfrmViewYard -1 7/27/2015 3:37 PM
TfrmChangeYard 1 7/27/2015 3:38 PM
TfrmInventory -1 7/27/2015 3:38 PM
TfrmViewYard 1 7/27/2015 3:38 PM
TfrmChangeYard -1 7/27/2015 3:38 PM
TfrmInventory 1 7/27/2015 3:38 PM
TfrmViewYard -1 7/27/2015 3:38 PM
TfrmChangeYard 1 7/27/2015 3:39 PM
TfrmInventory -1 7/27/2015 3:39 PM
TfrmInventory -1 7/27/2015 3:39 PM
TfrmInventory -1 7/27/2015 3:39 PM
TfrmChangeYard -1 7/27/2015 3:39 PM
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Repeated Release/Destroy  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 30, 2015 2:37 PM   in response to: William McDonald in response to: William McDonald
William McDonald wrote:

I have an application that occasionally throws an error because it is
attempting to free an object that has already been freed. All of the
forms have code in them that logs the creation and destruction of the
form in the corresponding event. Looking at the log for the session
that generated the error I see at the end that the OnDestroy event
was executed three times in a row. The only time a form is released
is when the user elects to move to a different form. There is no way
that normal execution of the program could release a form without
having created it first. And yet it happened. Has anyone seen this
behavior?

The code to change forms is as follows:
procedure TFramePgHdr.Move(AFormClass: TIWAppFormClass; FormName:
string); begin
  if TIWAppForm(WebApplication.ActiveForm).Name = FormName then
    exit;
  // Release the current form
  // Note that Intraweb keeps track of which forms exist
  TIWAppForm(WebApplication.ActiveForm).Release;
  // Create the next form
  if TIWAppForm(WebApplication.FindFormByName(FormName)) <> nil then
       TIWAppForm(WebApplication.FindFormByName(FormName)).Show
  else
       AFormClass.Create(WebApplication).Show;
end;


The log for the session is as follows: (ActionValue of 1=form
created, -1=form destroyed) FORM ACTIONVALUE DATECR
TfrmLogin 1 7/27/2015 3:36 PM
TfrmChangeYard 1 7/27/2015 3:36 PM
TfrmLogin -1 7/27/2015 3:36 PM
TfrmViewYard 1 7/27/2015 3:36 PM
TfrmChangeYard -1 7/27/2015 3:36 PM
TfrmRackSmry 1 7/27/2015 3:36 PM
TfrmViewYard -1 7/27/2015 3:37 PM
TfrmViewYard 1 7/27/2015 3:37 PM
TfrmRackSmry -1 7/27/2015 3:37 PM
TfrmInventory 1 7/27/2015 3:37 PM
TfrmViewYard -1 7/27/2015 3:37 PM
TfrmChangeYard 1 7/27/2015 3:38 PM
TfrmInventory -1 7/27/2015 3:38 PM
TfrmViewYard 1 7/27/2015 3:38 PM
TfrmChangeYard -1 7/27/2015 3:38 PM
TfrmInventory 1 7/27/2015 3:38 PM
TfrmViewYard -1 7/27/2015 3:38 PM
TfrmChangeYard 1 7/27/2015 3:39 PM
TfrmInventory -1 7/27/2015 3:39 PM
TfrmInventory -1 7/27/2015 3:39 PM
TfrmInventory -1 7/27/2015 3:39 PM
TfrmChangeYard -1 7/27/2015 3:39 PM

Hi Willian,

I have to check this code and your findings. Plese give me a few hours
and I'll get back to you.

BTW, once Embarcadero forum seems to have stability issues, please use
our news groups for support:
http://atozed.com/IntraWeb/Support/index.EN.aspx
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Repeated Release/Destroy  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 18, 2015 3:32 PM   in response to: William McDonald in response to: William McDonald
William McDonald wrote:

I have an application that occasionally throws an error because it is
attempting to free an object that has already been freed. All of the
forms have code in them that logs the creation and destruction of the
form in the corresponding event. Looking at the log for the session
that generated the error I see at the end that the OnDestroy event
was executed three times in a row. The only time a form is released
is when the user elects to move to a different form. There is no way
that normal execution of the program could release a form without
having created it first. And yet it happened. Has anyone seen this
behavior?

The code to change forms is as follows:
procedure TFramePgHdr.Move(AFormClass: TIWAppFormClass; FormName:
string); begin
  if TIWAppForm(WebApplication.ActiveForm).Name = FormName then
    exit;
  // Release the current form
  // Note that Intraweb keeps track of which forms exist
  TIWAppForm(WebApplication.ActiveForm).Release;
  // Create the next form
  if TIWAppForm(WebApplication.FindFormByName(FormName)) <> nil then
       TIWAppForm(WebApplication.FindFormByName(FormName)).Show
  else
       AFormClass.Create(WebApplication).Show;
end;


The log for the session is as follows: (ActionValue of 1=form
created, -1=form destroyed) FORM ACTIONVALUE DATECR
TfrmLogin 1 7/27/2015 3:36 PM
TfrmChangeYard 1 7/27/2015 3:36 PM
TfrmLogin -1 7/27/2015 3:36 PM
TfrmViewYard 1 7/27/2015 3:36 PM
TfrmChangeYard -1 7/27/2015 3:36 PM
TfrmRackSmry 1 7/27/2015 3:36 PM
TfrmViewYard -1 7/27/2015 3:37 PM
TfrmViewYard 1 7/27/2015 3:37 PM
TfrmRackSmry -1 7/27/2015 3:37 PM
TfrmInventory 1 7/27/2015 3:37 PM
TfrmViewYard -1 7/27/2015 3:37 PM
TfrmChangeYard 1 7/27/2015 3:38 PM
TfrmInventory -1 7/27/2015 3:38 PM
TfrmViewYard 1 7/27/2015 3:38 PM
TfrmChangeYard -1 7/27/2015 3:38 PM
TfrmInventory 1 7/27/2015 3:38 PM
TfrmViewYard -1 7/27/2015 3:38 PM
TfrmChangeYard 1 7/27/2015 3:39 PM
TfrmInventory -1 7/27/2015 3:39 PM
TfrmInventory -1 7/27/2015 3:39 PM
TfrmInventory -1 7/27/2015 3:39 PM
TfrmChangeYard -1 7/27/2015 3:39 PM

Hi Willian,

I have to check this code and your findings. Plese give me a few hours
and I'll get back to you.

BTW, once Embarcadero forum seems to have stability issues, please use
our news groups for support:
http://atozed.com/IntraWeb/Support/index.EN.aspx
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: Repeated Release/Destroy  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 18, 2018 4:07 PM   in response to: William McDonald in response to: William McDonald
William McDonald wrote:

I have an application that occasionally throws an error because it is
attempting to free an object that has already been freed.

Then you have a serious problem: your memory management is badly
designed. Try to improve that. Do not ask for tricks to remedy the
symptoms: improve your design.

With halfway proper design, you won't be facing such problems anymore,
because at all times, you will be knowing exactly when or if an item
can be freed or not. No need to guess anymore. Then you won't be able
to make any (memory management related) mistakes anymore, because you
can easily prevent them.

There are good books on the topic, e.g. Dalija Prasnikar's excellent
book on Delphi memory management.

--
Rudy Velthuis http://www.rvelthuis.de

"Nietzsche was stupid and abnormal."
-- Leo Tolstoy (1828-1910)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02