Removing objects ASAP from snapshot after invalidate call

In your tutorial on Snapshots, it is mentioned that “if you create a snapshot and don’t need to re-render or update its contents later, you can remove the objects that were used to create the snapshot and free up the related texture memory.”

Is there a proper way in which I should approach timing for removing these child objects as soon as possible? For example, since invalidate will “re-render the children to a texture on the next render pass.”, I’m looking for a way in which I can be 100% sure the image has finished rendering before I delete the objects.

If I, say, use a timer, how much time should I give after the invalidate call to be 100% assured the the re-rendering has finished? Would it vary on different devices? Or is there possible some type of callback or any other type of approach?

Thank you!

Hi @jhow,

I suppose to be as “safe” as possible, I would wait until the time step after the re-render has occurred, so effectively two time steps:

–current time step: invalidate the snapshot

–next time step: the snapshot is re-rendered

–next time step: remove the children

Now, if your app is running at 30 FPS, that would be 33.33 ms, doubled to 66.66, so 100 millseconds would be safe. If your app is running at 60 FPS, 16.67x2 = 33.33, so 50 milliseconds. I would go with 100 ms as defensive programming, unless that time is somehow “too long”.

Best regards,

Brent

Thanks for your response @Brent Sorrentino,

After experimenting with the timing, there were cases where I actually had to have a delay of up to 15 seconds sometimes or else I would not always see the object.

Anyways, due to a few complications with Snapshot (mainly Android suspend/resume related issues), I ended up just removing any use of snapshots I had. Thank you anyways for your time!

Hi @jhow,

I suppose to be as “safe” as possible, I would wait until the time step after the re-render has occurred, so effectively two time steps:

–current time step: invalidate the snapshot

–next time step: the snapshot is re-rendered

–next time step: remove the children

Now, if your app is running at 30 FPS, that would be 33.33 ms, doubled to 66.66, so 100 millseconds would be safe. If your app is running at 60 FPS, 16.67x2 = 33.33, so 50 milliseconds. I would go with 100 ms as defensive programming, unless that time is somehow “too long”.

Best regards,

Brent

Thanks for your response @Brent Sorrentino,

After experimenting with the timing, there were cases where I actually had to have a delay of up to 15 seconds sometimes or else I would not always see the object.

Anyways, due to a few complications with Snapshot (mainly Android suspend/resume related issues), I ended up just removing any use of snapshots I had. Thank you anyways for your time!