Coffeehouse Thread

25 posts

C# biggest awesome

Back to Forum: Coffeehouse
  • User profile image
    IDWMaster

    , elmer wrote

    For me, although it's more a .net thing... the garbage collector... and the fact that I can get away with being so damned lazy about cleaning up after myself... LOL.

    Don't be lazy with cleaning up after yourself! Even in C#. Just because it has a garbage collector, doesn't mean you can be that lazy. Always call Dispose() on IDisposables (including MemoryStreams, and ESPECIALLY Bitmaps), and I'm in the habit of setting everything to null when I'm done using it (not sure if it actually matters though; performance-wise). There are still SOME memory leaks in C# to watch out for. 

  • User profile image
    Richard.Hein

    , IDWMaster wrote

    *snip*

    Don't be lazy with cleaning up after yourself! Even in C#. Just because it has a garbage collector, doesn't mean you can be that lazy. Always call Dispose() on IDisposables (including MemoryStreams, and ESPECIALLY Bitmaps), and I'm in the habit of setting everything to null when I'm done using it (not sure if it actually matters though; performance-wise). There are still SOME memory leaks in C# to watch out for. 

     

    <sarcasm>I set everything to null 5x just to be sure, and terminate all lines with 5 ;'s just in case.</sarcasm>

    Disposing is important, yes, but setting stuff to null?  Pointless noise.  Stop it!  Perplexed 

     

  • User profile image
    felix9

    , IDWMaster wrote

    and I'm in the habit of setting everything to null when I'm done using it (not sure if it actually matters though; performance-wise).

     

    apparently this is a good habit if you are targeting CF or the phone.

    http://blogs.msdn.com/b/abhinaba/archive/2011/01/04/wp7-when-does-gc-consider-a-local-variable-as-garbage.aspx

  • User profile image
    staceyw

    It is the dot.  Overlooked today. But the dot in dot.net changed everything from prior vb6 days.  It made the clean namespace and fx possible and the intellisense and tied everything in together.  Which also led to organized and contexful documentation.  The dot rules. 

  • User profile image
    elmer

    , IDWMaster wrote

    *snip*

    Don't be lazy with cleaning up after yourself! Even in C#. Just because it has a garbage collector, doesn't mean you can be that lazy.

     

    How about... don't be so quick to assume and lecture.

     

    I was talking about working in a managed environment, vs. unmanaged - hence the reference to it being more of a .net thing.

  • User profile image
    Richard.Hein

    Thanks for the information, it is good to know.  It does say, however that it's only important when: "... you have locals that hold onto very large data structures and that function will remain executing for a long time then set those variables to null when you are done using them (e.g. in between the last usage of a variable in a large function and calls to a bunch of web-services in the same function which will take a long time to return)."  To clarify things, as mentioned in the link, the full CLR does analysis to figure when a local variable no longer is in use at JIT time.  However CLI implementations are not required to do so, and the CF doesn't, due to resource limitations.  Good info, thanks Felix9.

  • User profile image
    SteveRichter

    I am getting a lot of mileage out of extension methods. It was a great day when I found out you could code extension methods for interfaces and enums as well as classes. Simply as a way to organize code, where I place methods that apply to an interface or enum in a static class in the same file as the interface/enum.  Something else useful about extension methods is  the this object can be null and the extension method will still be called. Which is not the case with a method of a class.

     

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.