anonymous function Access external variables have GC

Source: Internet
Author: User

Directly on the test code:

usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine; Public classteststructgc:monobehaviour{ Public structStructdef { PublicSystem.Action Act;  PublicStructdef (system.action callback) {Act=callback; }    }     Public intMembervalue; Private voidUpdate () {//using anonymous functions, not accessing external functions, 0 GC{UnityEngine.Profiling.Profiler.BeginSample ("* * * * Test1"); Structdef obj=NewStructdef (NULL);        UnityEngine.Profiling.Profiler.EndSample (); }        //use anonymous functions, access temporary variables, 112B GC        {            intTMP =1; UnityEngine.Profiling.Profiler.BeginSample ("* * * * Test2"); Structdef obj=NewStructdef (() = {varv =tmp;});        UnityEngine.Profiling.Profiler.EndSample (); }        //using anonymous functions, accessing external variables, 112B GC{UnityEngine.Profiling.Profiler.BeginSample ("* * * * TEST3"); Structdef obj=NewStructdef (() ={debug.logerror (membervalue);            });        UnityEngine.Profiling.Profiler.EndSample (); }        //do not use anonymous functions, 0 GC{UnityEngine.Profiling.Profiler.BeginSample ("* * * * TEST4"); Structdef obj=Newstructdef (Actcallback);        UnityEngine.Profiling.Profiler.EndSample (); }    }    #regionOptimize for Test4PrivateSystem.Action Actcallback;  PublicTESTSTRUCTGC () {Actcallback=Localcallback; }    Private voidLocalcallback () {debug.logerror (membervalue); }    #endregion}

Reference: https://blog.uwa4d.com/archives/Anonymous_heapmemory.html

anonymous function Access external variables have GC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.