unity3d - High memory allocations when unregistering delegates from event in C# -



unity3d - High memory allocations when unregistering delegates from event in C# -

we developing game unity3d engine (which uses mono user code - our code written in c#).

the scenario have class exposing event, around ~ 250 registrations event (each level object on game's map registers event):

// every level registers (around 250 levels) scoresdatahelper.onscoresupdate += handleonscoresupdate;

when destroying scene, every object unregisters event:

scoresdatahelper.onscoresupdate -= handleonscoresupdate;

when using built-in profiler, seeing huge memory allocation, digging deeper shows due delegates beingness unregistered.

i suspect due fact delegates immutable , when chaining them together, new instances created ?

here's screenshot unity's profiler:

is there way avoid these memory allocations when dealing big number of event subscriptions?

as confirmed in comments want unsubscribe event subscriptions, there no reason unsubscribe 1 one.

you set event null. unsubscribe event without allocating memory.

this.onscoresupdate = null;

one thing note can't outside of scoresdatahelper class. must within scoresdatahelper class.

c# unity3d mono

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -