Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Exception in inherited destroy

106 views
Skip to first unread message

Marc Pelletier

unread,
May 23, 2000, 3:00:00 AM5/23/00
to
Hello all,

I have a class which has only 1 dynamic array, some integers and a floating
point as data. I've exposed this class via a DLL to another programming
environment. Its all declared as follows:

type TLineDir = class
private
MinDist, Position: Integer;
iStart, iEnd: Integer;
DirSense: single;
Directions: array of single;
public
constructor GeoCreate(hGeo: Integer; var XVV,YVV: Integer;var iMinDist:
Integer;var rDirSense: double);
function GetSegment(hGeo: Integer; var iMin, iMax: Integer; iGaps:
Integer): Integer;
// returns a 1 if more segments exists, else 0
destructor Destroy;override;
end;

It mostly works but it consistently throws an access violation error at a
particular point in my data. I've chased the exception down to the last line
of the DeleteFree procedure in GetMem.inc. This is called during the
inherited Destroy method called by my class destructor, like this:

destructor TLineDir.Destroy;
begin
Directions := nil;
inherited;
end;

The DeleteFree method, from GetMem.inc, is below:

procedure DeleteFree(f: PFree);
var
n, p: PFree;
size: Integer;
begin
if rover = f then
rover := f.next;
n := f.next;
size := f.size;
if size <= cSmallSize then begin
if n = f then
smallTab[size div cAlign] := nil
else begin
smallTab[size div cAlign] := n;
p := f.prev;
n.prev := p;
p.next := n;
end;
end else begin
p := f.prev;
n.prev := p;
p.next := n;
end;
end;


I would appreciate any help in this, as once I get into the Delphi dcu stuff
I am pretty lost.

Thanks

Marc Pelletier


-----------------------------------------------------------------------------
--
Data Donkey - Geophysical Data Processing, Consulting and Software
Development
Creator of the POWER TOOLBOX utilities for OASIS montaj
contact: ma...@datadonkey.com tel (306) 931-6853 or www.datadonkey.com

Carlos Mateo

unread,
May 23, 2000, 3:00:00 AM5/23/00
to
In the destructor you assign nil to Directions. If the memory used by
Directions was not freed, the inherited method may try to access this
memory, and this will cause an error.
I hope this will help you.

Howard Moon

unread,
May 23, 2000, 3:00:00 AM5/23/00
to
Could it be that f.prev is nil, so that p is then nil, and thus p.next is
not valid? If so, you could add a check:

if p <> nil then
p.next := n;

-Howard

Marc Pelletier

unread,
May 23, 2000, 3:00:00 AM5/23/00
to
Howard Moon wrote in <8gecoh$sp...@bornews.borland.com>:

>Could it be that f.prev is nil, so that p is then nil, and thus p.next is
>not valid?

Well, anything could be I guess, but this is in some of the Borland code that
gets called just about anytime you free something, as far as I can tell, so I
doubt there is a bug there. I step through a whole bunch of BASM before I get
to this particular routine, so I really don't have a clue what is going on at
this point though.

cheers

Marc



-----------------------------------------------------------------------------

John Elrick

unread,
May 23, 2000, 3:00:00 AM5/23/00
to
Try commenting out the Directions := nil and see if you get the same
results. Since the only thing you can safely nil to destroy is an
interface, I have a suspicion that your problem might be there.

Could be wrong though. I don't use arrays very often, I use lists instead.


John

"Marc Pelletier" <Ma...@StopSpam.DataDonkeycom> wrote in message
news:8F3D68...@10.10.135.115...


> Hello all,
>
> I have a class which has only 1 dynamic array, some integers and a
floating
> point as data. I've exposed this class via a DLL to another programming
> environment. Its all declared as follows:
>
> type TLineDir = class
> private
> MinDist, Position: Integer;
> iStart, iEnd: Integer;
> DirSense: single;
> Directions: array of single;

> destructor TLineDir.Destroy;

Marc Pelletier

unread,
May 24, 2000, 3:00:00 AM5/24/00
to
John Elrick wrote in <392ac978@dnews>:

>Try commenting out the Directions := nil

Well, the help file states:
"To deallocate a dynamic array, assign nil to a variable that references the
array"

I've tried using a SetLength(Directions,0) statement instead of, and in
addition to, with the same results. I've also commented out the call to the
inherited destroy, with no luck.

The failure always happens at the same point in the data.

Any more ideas?

Thanks

John Elrick

unread,
May 24, 2000, 3:00:00 AM5/24/00
to
No. At least you've got it tied down to the one line.

Without seeing the rest of your code, I'm a bit lost - but as a suggestion,
I've found it far easier to maintain a list of objects. Even easier in D5
with TObjectList.

TDirection = class
FValue : single;
public
property Value : single read FValue;
constructor Create(const Value : single);
end;
Looks like overkill for your job, but you may have more information and work
that should be delegated to this class than you may think.

John

"Marc Pelletier" <Ma...@StopSpam.DataDonkeycom> wrote in message

news:8F3E50...@207.105.83.62...

David Marcus

unread,
May 25, 2000, 3:00:00 AM5/25/00
to
Marc Pelletier wrote:

> It mostly works but it consistently throws an access violation error at a
> particular point in my data. I've chased the exception down to the last line
> of the DeleteFree procedure in GetMem.inc. This is called during the
> inherited Destroy method called by my class destructor, like this:
>

> destructor TLineDir.Destroy;
> begin
> Directions := nil;
> inherited;
> end;

Sounds like something else is trashing memory, but you don't get an
exception until this point. Try using the debugger, and making sure the
array is OK.

--
David Marcus

Marc Pelletier

unread,
May 25, 2000, 3:00:00 AM5/25/00
to
David Marcus wrote in <MPG.13973d3e5...@newsgroups.inprise.com>:

>Sounds like something else is trashing memory, but you don't get an
>exception until this point. Try using the debugger, and making sure the
>array is OK.
>

I've confirmed that right up until a call to SetLength(Directions,0) the
array is ok, well it's data is still ok, Im not sure how to check the hidden
stuff. When I try to step past the SetLength call I get the exception.

0 new messages