Creta Park
banner
cretapark.me
Creta Park
@cretapark.me
About me : https://creft.me/cretapark
- Korean, English OK!
- Indie game developer and C# programmer.
- Working on SunnySideUp and @stations.cretapark.me

* Repost, opinions do not represent the company.
+ Correction is welcome!
November 25, 2025 at 4:25 AM
It's mostly can be happened on creating/loading non-GameObject native instance.

In our case, some external asset make this trouble causes memory leak and it's hard to find root causes during profiling memory...

So make sure to free referencing instances on end of life-cycle!

🧵

#unitytips
November 25, 2025 at 4:21 AM
The solution is make it explicitly assigning null to member on end of life-cycle.

class NI {
...
void OnDestroy() {
if (Child != null)
Child.Parent = null;
Child = null;
}
}

It'll break both of references so GC and asset system can free/unload these instances!

🧵

#unitytips
November 25, 2025 at 4:21 AM
Here's the reason :

- NI has reference count from it's Child member's instance member, _parent, this causes NI's managed wrapper instance still be alived on memory.
- MI has reference from native instance, NI's member, Child, causes GC cannot sure it's okay to free that instance.

🧵

#unitytips
November 25, 2025 at 4:21 AM
For example :

class NI : ScriptableObject {
public MI Child;
}

class MI {
public NI Parent;
public MI(NI parent) {
Parent = parent;
}
}

NI asset = ...;
asset.Child = new MI(asset);

This causes cyclic reference so it cannot be freed completely even `Destroy(asset)`.

🧵

#unitytips
November 25, 2025 at 4:21 AM
You should deserve have some credits that fills entire screen
November 25, 2025 at 12:17 AM
Yoo it's already feels satisfying
November 21, 2025 at 6:39 AM
Unity Object is somehow cursed...
November 14, 2025 at 12:28 AM