Download

TWeakObjectPtr thread safe validity

Hi!

If using TWeakObjectPtr (for example from render thread) and calling IsValid(true, true), can one be certain that the validity of that result will live through the scope where IsValid is called?

I need this to be certain that the GC will not collect memory while render thread is still using the object. I read somewhere in the documents that GC cleanup is synced however it can trail one or two frames behind.

I know there is FGCScopeGuard but I’m worried that will be overkill and lowers the performance significantly since it will stall the GC on other thread (afaik). Weak pointer seems much more lighter option.

Thanks!

Just looking at the code, it seams that it is kind of designed to be used by non-game threads…

/**  
 * Test if this points to a live UObject
 * @param bEvenIfPendingKill, if this is true, pendingkill are not considered invalid
 * @param bThreadsafeTest, if true then function will just give you information whether referenced 
 *							UObject is gone forever  @return false) or if it is still there  @return true, no object flags checked).
 * @return true if Get() would return a valid non-null pointer, if bThreadsafeTest == true then @see @param bThreadsafeTest
**/
COREUOBJECT_API bool IsValid(bool bEvenIfPendingKill, bool bThreadsafeTest = false) const;