DotNetKick.com is an open-source project. Please report any bugs and let us know your great suggestions. Currently running svn revision 620 (rss)

Kick Spy!, Kick Zeitgeist and Kick Widgets

5
kicks
submitted by animaonline animaonline 9 months, 17 days ago

softscenario.blogspot.com — When writing code that makes use of alot of unmanaged memory resources, all objects should be disposed of before exiting methods and such. The keyword using is often forgotten, and also sometimes seen as messy. example: using (Bitmap bitmap1 = new Bitmap(100, 100)) { Console.WriteLine("Width:{0}, Height:{1}", bitmap1.Width, bitmap1.Height); } should basically be the same as Bitmap bitmap1 = new Bitmap(100, 100) Console.WriteLine("Width:{0}, Height:{1}", bitmap1.Width, bitmap1.Height); bitmap1.Dispose(); shouldn't it? No, not really... The using-clause does a little more than this. Actually, my using-example is equivalent to the following block of code. Bitmap bitmap1 = new Bitmap(100, 100); try { Console.WriteLine("Width:{0}, Height:{1}", bitmap1.Width, Bitmap1.Height); } finally { if (bitmap1 != null) { bitmap1.Dispose(); } } Console.ReadLine(); Imagine writing nested using-clauses, and try writing the expanded code for that :) Using using really cleans up your code, and your memory. So use it! Edit: Oh, as Stian commented. Using should be used for all objects that implements the IDisposable interface. But remember - if you plan on implementing this interface on your own classes, you need to make sure it fully implements all the necessary methods for cleaning up. Otherwise it will all be to waste :)

Add a comment add a comment | category: | Views: 1 | Get KickIt image code
tags: , , , | tag it

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:

Comments:

No comments so far




information Login or create an account to comment on this story
 

Sponsored Link: www.carlist.ie

Search:

Ads via The Lounge