FStreamableManager is not GC safe

I have been recently starting using the FStreamableManager, and I believe it doesn’t account for garbage collected objects properly. Everywhere in the wiki and documentation is suggested to access the FStreamableManager globally, from a singleton class, although when you do so, it is very likely that you will incur into the following issue.

FStreamableManager has as propery

typedef TMap TStreamableMap;
TStreamableMap StreamableItems;

This map will be later used as a fast look up table not to re-load an object if already loaded. Although, because this map is not known to the GC (not a UPROPERTY and not a TArray), the UObject raw pointer stored in the FStreamable object (UObject* Target) is likely to be recycled. Therefore if the code is trying to load the same asset more than once, the streamable manager will find a reference in its map, although, the returned target pointer will point to a different object, invalidating the very initial reason for this map to exist.

I do understand that you might don’t want to keep objects around in memory, hence the loose reference, although I find this interface at least easy to mis-use.

Simple solution for me at the moment is not to store a global FStreamableManager and re-declare one every time I need to load an asset.

Hope this helps to figure out some random crashes while using this API.

I think there is couple of methods to release the handle from this manager
However it is sad that we should manage the FStreamableManager memory as well.

The biggest caveat for us to know when we want to release the handles :expressionless:
If multiple objects are involved then it is a headache.

Maybe we should let the manager to keep a hard ref to the asset, and explicitly release it when we know for sure that we don’t need it anymore.

Redeclare every time adds more bugs as well - for example if your actor asked for async loading
but it is destroyed before the manager loaded everything and GC ticked and the same time → we will have another crash.