Re: Exception-Objekt freigeben



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.
.



Relevant Pages

  • Re: Validating file names
    ... running Novel, from your G: running Linux file system, from your H: running ... I am not saying one does not exist! ... file file and handle any exceptions that were thrown. ... If an exception is thrown then the specified ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Using an ActiveX ocx control on a Webform
    ... > download the ActiveX I can Automate the ActiveX object through the ... > Exception of type InvalidActiveXStateException was thrown. ... > tried using the item in the design mode of a regular .NET Windows ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: exception handling in complex Python programs
    ... errors possibly thrown by open, or leave it to the caller? ... def do_something: ... have to couple the exception type with the function --- between file ... Python 3 and an IOError is thrown in the other three cases <bashes ...
    (comp.lang.python)
  • Re: how to change method return type from void to boolean
    ... Will the method return in case of exception thrown ... final OperationListener operationListener) { ... However my problem is that I need to determine what was wrong and show it to the user (in gui layer). ...
    (comp.lang.java.programmer)
  • Re: Question about Authorization Manager
    ... They do throw an exception if an empty task is passed for a check. ... second message to be thrown, but I'm guessing that it's a similar ... security block code. ... But I understand that you believe what I was describing was referring to an empty task, i.e. one not containing any operations or nested tasks that contain operations, and this is where we are not in sync with one another. ...
    (microsoft.public.dotnet.security)