Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 20 of 21 total
Thread Access Violation when freeing table
Wed, Mar 22 2006 1:09 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Bern


Random strikes a chord. I do get it, for memory tables, and (I think) only in the IDE, and only for MDIChild forms when I close the app, not the form.

I think what's happening in those circumstances is the datamodule/session/database/engine (note the sureness here) is freed BEFORE I try and free the table and that frees the table.

Probably totally unrelated Smiley

Roy Lambert
Wed, Mar 22 2006 8:27 PMPermanent Link

Hi Roy,

> 1. I never got into assembler - tried and failed

Translation...

procedure TObject.Free;
begin
if Self <> nil then
  Self.Destroy;
end;

> 2. I that case why do I get AV's when trying to free an object that's
> already been freed?

Because freeing the object does not set any object variables to nil.
Your suggestion to wrap the call to free in a test for assigned
effectively translates into...

if table <> nil then
 if table <> nil then
   table.destroy;
   
Try instead...
 table.free;
 table := nil;
and then next time you try to free it there will be no exception.
 
Or even better, you could use...
 FreeAndNil(table);  


Quote...

procedure FreeAndNil ( var ObjectReference ) ;

Description
The FreeAndNil procedure frees up the memory used by an object, and sets
the object reference to nil.

It actually does this in reverse order - first dereferencing the object
before deallocating the memory. This is a very clean way of freeing
resources, so if an exception occurs in the destructor of the object, the
reference will be Nil anyway.

Example code : Free and nil an object, and then try to do this again
var
 myList : TList;

begin
 // Create the list object
 myList := TList.Create;

 // And now free and nil this object
 FreeAndNil(myList);

 // We can safely do this twice - it ignores nil objects
 FreeAndNil(myList);
end;

No exception occurs - the second FreeAndNil does nothing.

....endquote.


--Bill Sparrow--


Thu, Mar 23 2006 4:22 AMPermanent Link

"Frans van Daalen"

"Bern Rudisill" <bernr@no-sp.am.exitcare dot com> wrote in message
news:AEC1781C-CF9D-4AE0-9AEF-0849E6E9F629@news.elevatesoft.com...
> Tim Young [Elevate Software] wrote:
>
>> Bern,
>>
>> << For some reason I am randomly getting an AV when I free tables.
>> Here is a snip from the bug report I am getting (I have also attached
>> the bug report in case it helps). Basically at line 8702 in my data
>> module I am doing a .free of the table then I get the AV. >>
>>
>> Is there any chance that the data module's components are being
>> improperly shared between threads ?  That's where I would start
>> looking.
>
> Each component is created dynamically in the data module to be thread
> safe. But even so the procedure that is having the problem is not used
> by a thread.
>
> Bern
>
> --
Did you assign a owner in the create  or use NIL? Having an owner could
explain this as the owner will try to free his owned objects.

Thu, Mar 23 2006 6:20 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Bill


You've sold me. Once I've beaten D2006 into submission I'll change my Free's to FreeAndNil's
Roy Lambert
Thu, Mar 23 2006 7:15 AMPermanent Link

"Bern Rudisill"
Frans van Daalen wrote:

>
> "Bern Rudisill" <bernr@no-sp.am.exitcare dot com> wrote in message
> news:AEC1781C-CF9D-4AE0-9AEF-0849E6E9F629@news.elevatesoft.com...
> > Tim Young [Elevate Software] wrote:
> >
> > > Bern,
> > >
> > > << For some reason I am randomly getting an AV when I free tables.
> > > Here is a snip from the bug report I am getting (I have also
> > > attached the bug report in case it helps). Basically at line 8702
> > > in my data module I am doing a .free of the table then I get the
> > > AV. >>
> > >
> > > Is there any chance that the data module's components are being
> > > improperly shared between threads ?  That's where I would start
> > > looking.
> >
> > Each component is created dynamically in the data module to be
> > thread safe. But even so the procedure that is having the problem
> > is not used by a thread.
> >
> > Bern
> >
> > --
> Did you assign a owner in the create  or use NIL? Having an owner
> could explain this as the owner will try to free his owned objects.

The datamodule is the owner, which is only freed when shutting down the
program.

Bern

--
Thu, Mar 23 2006 7:16 AMPermanent Link

"Bern Rudisill"
Roy Lambert wrote:

> Bill
>
>
> You've sold me. Once I've beaten D2006 into submission I'll change my
> Free's to FreeAndNil's Roy Lambert

I started using FreeAndNil's awhile ago and it solved a lot of problems
I once had

Bern
--
Thu, Mar 23 2006 3:44 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Bern,

<< Nope I checked the code and there is only 1 place where the table is
freed in the entire project.

BTW I see I did not put it in the orginal post, but this is random. >>

Does it occur often enough that you could possibly send me something to try
?  Frankly, at this point I have no idea what could be causing it other than
what has already been covered by myself and others.  A Free/Destroy is a
fairly straightforward affair as long as the instance variable is pointing
to a valid instance of the object.

--
Tim Young
Elevate Software
www.elevatesoft.com

Thu, Mar 23 2006 4:37 PMPermanent Link

"Bern Rudisill"
Tim Young [Elevate Software] wrote:

> Bern,
>
> << Nope I checked the code and there is only 1 place where the table
> is freed in the entire project.
>
> BTW I see I did not put it in the orginal post, but this is random. >>
>
> Does it occur often enough that you could possibly send me something
> to try ?  Frankly, at this point I have no idea what could be causing
> it other than what has already been covered by myself and others.  A
> Free/Destroy is a fairly straightforward affair as long as the
> instance variable is pointing to a valid instance of the object.

Sorry I have not been able to consistantly reproduce it, I have had it
a few times a about 3 sites that use our software.

--
Fri, Mar 24 2006 1:18 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Bern,

<< Sorry I have not been able to consistantly reproduce it, I have had it a
few times a about 3 sites that use our software. >>

I would suspect that it has something to do with the order of the freeing.
For now, I would make sure that you're nil-ing any freed object references
in case something is trying to get freed twice.

BTW, could you post the code for the TDM.SaveToRecentPatients method ?

Thanks,

--
Tim Young
Elevate Software
www.elevatesoft.com

Sat, Mar 25 2006 12:53 PMPermanent Link

If you are doing the freeing yourself in code, then you should supply nil
as the owner in the Create.

--Bill Sparrow--
« Previous PagePage 2 of 3Next Page »
Jump to Page:  1 2 3
Image