[Development] Suggestion: how to know when object is scheduled for deletion
Thiago Macieira
thiago.macieira at intel.com
Fri May 6 01:00:18 CEST 2016
On quinta-feira, 5 de maio de 2016 19:09:59 PDT Sean Donnelly wrote:
> In our application we maintain a UI Inventory via a named object cache.
> When an object is destroyed we remove it from our cache and when the name
> is changed we also update our cache.
>
> However when an object is scheduled for deletion via QObject::deleteLater()
> the object remains in our cache until it's actually deleted.
>
> I have two proposals:
>
>
> 1. Could deleteLater() send a signal so that we can update our cache
> immediately and not find that UI object which is about to be deleted.
The signal is destroyed() and is sent as soon the object actually gets
deleted.
> 2. Could deleteLater() set a property to know the object is in an
> "about to be deleted state". That way our UI Inventory could be updated to
> ignore these objects.
That's a bad idea.
If you deleteLater() an object in the current thread, the object is really not
deleted and may still work fine. However, if you do that for an object in
another thread, the object may get deleted immediately, so you can't touch the
object anymore and you can't get to the property.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Development
mailing list