So, I’m planning on making a tower defense game, and I was wondering if TargetFilter will cause memory leaks for the placement after destroying the models.
Yes it will cause a memory leak since the property still is a strong reference to the destroyed model, if possible listen for AncestryChanged
and check if new parent is nil assuming you don’t parent things to nil temporarily.
Wait so is there any way to actually check if something is destoryed. I don’t parent things to nil, but if I might accidently I don’t want to cause strange bugs by removing it from the targetfilter.
it can be argued this doesn’t quite classifies as a memory leak, as TargetFilter
can only stores 1 instance at a time and wouldn’t infinitely pile up data each time it’s changed (it’d just get replaced with the new data or hang around as a single unused value indefinitely if not touched). though it’s still by definition a bad practice it isn’t that practical to resolve when the performance decrease is practically non-existent
Agreed however, the instance is still there hanging around.
I did some testing and apparently TargetFilter
does gets garbage collected once the referenced instance is completely destroyed (output is printing the current filter)