Re: Exception-Objekt freigeben
- From: Markus Springweiler <springy@xxxxxx>
- Date: Mon, 31 Mar 2008 18:50:13 +0200
Arno,
Wenn ich mit AcquireExceptionObject das Objekt in meiner
Variabel zwischenspeichere und später ReleaseExceptionObject
aufrufe um es freizugeben, produziere ich ein Speicherleck.
Laut Doku musst du dich selbst um die Zerstörung (.Free) kümmern:
{
When an exception is thrown, the exception object that is thrown is destroyed
automatically when the except clause which handles the exception is exited.
There are some cases in which an application may wish to acquire the thrown
object and keep it alive after the except clause is exited. For this purpose,
we have added the AcquireExceptionObject and ReleaseExceptionObject functions.
These functions maintain a reference count on the most current exception object,
allowing applications to legitimately obtain references. If the reference count
for an exception that is being thrown is positive when the except clause is exited,
then the thrown object is not destroyed by the RTL, but assumed to be in control
of the application. It is then the application's responsibility to destroy the
thrown object. If the reference count is zero, then the RTL will destroy the
thrown object when the except clause is exited.
}
Mit AcquireExceptionObject und ReleaseExceptionObject änderst du nur den
Referenzzähler der Exception *UND* dieser wird auch nur beim Beenden des
try-except-Blocks geprüft. Wenn die Exception das überlebt, ist sie ein
ganz normales 0815-Objekt.
Die Delphi-Hilfe zum Thema ist offenbar fehlerhaft denn in
System.pas steht:
procedure ReleaseExceptionObject;
begin
end;
No, in System.pas sind min. 2 Implementationen davon, je nach
Compiler-Switches. Die normale enthält Assemblercode, welchen den
Referenzzähler anpasst, was aber (s.o.) nur innerhalb des try-except-Blocks
relevant ist.
--
/\/\arkus.
.
- Follow-Ups:
- Re: Exception-Objekt freigeben
- From: Arno Garrels
- Re: Exception-Objekt freigeben
- References:
- Exception-Objekt freigeben
- From: Arno Garrels
- Exception-Objekt freigeben
- Prev by Date: Re: Speicherleck finden - RegisterClass ?
- Next by Date: Re: Exception-Objekt freigeben
- Previous by thread: Exception-Objekt freigeben
- Next by thread: Re: Exception-Objekt freigeben
- Index(es):
Relevant Pages
|