开发者

TAutoObject in delphi lifecycle..?

I have a simple automation class like this:

type
  TTest_COM = class(TAutoObject, ITest_COM)
  private
    Variable: TClass;
  protected
    procedure Test(parameters...); safecall;
  public
    procedure  Initialize; override;
    destructor Destroy; override;
  开发者_高级运维end;

implementation

destructor TTest_COM.Destroy;
begin
  Variable.Free;
  inherited;
end;

procedure TTest_COM.Initialize;
begin
  inherited;
  Variable := TClass.Create;
end;

procedure TTest_COM.Test(parameters...); safecall;
begin
  // this method makes use of "Variable"
end;

Could anyone explain to me the lifecycle of such com object which acts as a msmq receiver?

The problem is that the procedure: Test sometimes operates on not allocated "Variable". When I remove the line: Variable.Free; It works perfectly okay in spite of the fact that the memory usage for the dllhost.exe grow up.

Why do such things happen?

EDIT:

Because I cannot answer on my own question. I am doing this here.

The problem solved.

The class was allocating the global variable. I haven't noticed that.

That was the problem that another variable was overwritten.

Thanks for your help!


The AutoObject should be freed when the reference count hits zero.

I suspect that the error is not in your code, but in the code that uses the object. In the code that uses your object the reference count hits zero and is destroyed, but the Test procedure is still called from that code on the freed object. That is why Test sometimes operates on a not allocated Variable: the TTest_COM object is already destroyed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜