unity3d - Dispose found in existing C# code. Should I get rid of it? -


i found following code in unity3d project using kinect v2 have taken over. i'm paranoid thought i'd check before delete it. surely there no reason these 2 lines??

colorframe.dispose(); colorframe = null; 

this c#. has automatic garbage collection understanding colorframe disposed when convenient outside of if(getrgb) statement

if (getrgb) {     colorframe colorframe = frame.colorframereference.acquireframe ();     if (colorframe != null)     {         colorframe.copyconvertedframedatatoarray (_colordata, colorimageformat.rgba);         _colortexture.loadrawtexturedata (_colordata);         _colortexture.apply ();         colorframe.dispose ();         colorframe = null;     } } 

it has automatic garbage collection understanding colorframe disposed when convenient outside of if(getrgb) statement

the object cleaned once gc kicks in (at non-deterministic time) , sees there no root colorframe object. calling dispose on object releases unmanaged resources allocated same object, calls gc.supressfinalize, makes object has finalizer de-register finalization queue, allowing gc clean "faster".

i suggest keeping call dispose. remove colorframe = null call, useless.

better yet, wrap colorframe in using statement:

if (getrgb) {     using (colorframe colorframe = frame.colorframereference.acquireframe())      {         if (colorframe != null)         {            colorframe.copyconvertedframedatatoarray(_colordata, colorimageformat.rgba);            _colortexture.loadrawtexturedata(_colordata);            _colortexture.apply();         }     } } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -