Discussion:
Access violation?
(too old to reply)
jodleren
2010-12-16 16:31:41 UTC
Permalink
Hi all!

In a form, I use a custom component, which uses 2 TImages and 2 arrays
of boolean.

On a form, I have a TCollection, where I create a number of these
components.

But, when destroying the form, I get an access violation, after
destroying 9 of 28 components, when setting the array of boolean to 0
- the FWinner.
Next, when I try to open the window again I get yet another access
violation, and I cannot recover from that.
It has to be some kind of memory leak, right? Any ideas what to look
for?

destructor TLottoBox.Destroy;
begin
try
FImg.Destroy;
FImg2.Destroy;
SetLength(FChecked, 0);
SetLength(FWinner, 0); // access violation here.
except
end;
inherited;
end;
jodleren
2010-12-16 19:54:24 UTC
Permalink
Post by jodleren
Hi all!
In a form, I use a custom component, which uses 2 TImages and 2 arrays
of boolean.
On a form, I have a TCollection, where I create a number of these
components.
But, when destroying the form, I get an access violation, after
destroying 9 of 28 components, when setting the array of boolean to 0
- the FWinner.
Next, when I try to open the window again I get yet another access
violation, and I cannot recover from that.
It has to be some kind of memory leak, right? Any ideas what to look
for?
destructor TLottoBox.Destroy;
begin
  try
    FImg.Destroy;
    FImg2.Destroy;
    SetLength(FChecked, 0);
    SetLength(FWinner, 0); // access violation here.
  except
  end;
  inherited;
end;
The problem was the array. When I set the array to a fixed size, I
dont have any problems.
So I just set it to 100, which is way more than I ever may need.

Sonnich
Maarten Wiltink
2010-12-16 22:59:46 UTC
Permalink
Post by jodleren
Post by jodleren
In a form, I use a custom component, which uses 2 TImages and 2 arrays
of boolean.
Dynamic arrays?
Post by jodleren
Post by jodleren
On a form, I have a TCollection, where I create a number of these
components.
But, when destroying the form, I get an access violation, after
destroying 9 of 28 components, when setting the array of boolean to 0
- the FWinner.
Next, when I try to open the window again I get yet another access
violation, and I cannot recover from that.
It has to be some kind of memory leak, right? Any ideas what to look
for?
A memory leak does not manifest as an access violation.
Post by jodleren
Post by jodleren
destructor TLottoBox.Destroy;
begin
try
FImg.Destroy;
FImg2.Destroy;
SetLength(FChecked, 0);
SetLength(FWinner, 0); // access violation here.
except
end;
inherited;
end;
The problem was the array. When I set the array to a fixed size, I
dont have any problems.
So I just set it to 100, which is way more than I ever may need.
You have not shown anything that could cause an access violation.
Setting the array is almost certainly not the problem. Nor is it the
solution.

Groetjes,
Maarten Wiltink

Loading...