Home Delphi ITask - should I free it after completed?
Reply: 1

Delphi ITask - should I free it after completed?

Gabor Published in 2018-02-12 11:15:28Z

I create an ITask (TTask.Create(...)). It works as expected. After it finishes the job, the task status shows me "completed".

Should I free the ITask object somehow, or it is freed automatically?

LU RD Reply to 2018-02-12 18:45:22Z

As with any interface that implements TInterfacedObject in their descendants (default), ITask is reference counted. This means that it will self-destruct, once its reference count is zero. This means that you don't have to free it manually.

See Memory Management of Interface Objects:

One of the concepts behind the design of interfaces is ensuring the lifetime management of the objects that implement them. The _AddRef and _Release methods of IInterface provide a way to implement this lifetime management. _AddRef and _Release track the lifetime of an object by incrementing the reference count on the object when an interface reference is passed to a client, and will destroy the object when that reference count is zero.

If the task is finished, it is also possible to destroy FTask by assigning a nil value. That will also decrement the reference count.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301748 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO