delphi生命周期中的TAutoObject..?
我有一个像这样的简单自动化类:
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;
任何人都可以向我解释充当 msmq 接收器的此类 com 对象的生命周期吗?
问题在于该过程:测试有时会在未分配的“变量”上运行。 当我删除这一行时:Variable.Free;尽管 dllhost.exe 的内存使用量增加了,但它仍然可以正常工作。
为什么会发生这样的事情呢?
编辑:
因为我无法回答我自己的问题。我在这里做这个。
问题解决了。
该类正在分配全局变量。我还没有注意到这一点。
这就是另一个变量被覆盖的问题。
感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当引用计数为零时,应释放 AutoObject。
我怀疑错误不在您的代码中,而是在使用该对象的代码中。在使用对象的代码中,引用计数为零并被销毁,但仍从释放对象上的代码调用
Test
过程。这就是为什么Test
有时会对未分配的变量进行操作:TTest_COM
对象已经被销毁。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 whyTest
sometimes operates on a not allocated Variable: theTTest_COM
object is already destroyed.