code_junkie

What's the point of the garbage collector

Nov 11th, 2011
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. SqlConnection connection = new SqlConnection(FROM_CONFIGURATION)
  2. SqlCommand command = new SqlCommand("SomeSQL", connection);
  3. connection.Open();
  4. command.ExecuteNonQuery();
  5. command.Dispose();
  6. connection.Dispose();
  7.  
  8. class MonkeyGrabber : IDisposable {
  9. public MonkeyGrabber() { /* construction grabs a real, live monkey from the cage */
  10. public void Dispose() { Dispose(true); /* releases the monkey back into the cage */ }
  11. // the rest of the monkey grabbing is left as an exercise to grad student drones
  12. }
  13.  
  14. class MonkeyMonitor {
  15. public void CheckMonkeys() {
  16. if (_monkeyPool.GettingTooRowdy()) {
  17. MonkeyGrabber grabber = new MonkeyGrabber();
  18. grabber.Spank();
  19. }
  20. }
  21. }
  22.  
  23. using (SqlConnection connection = new SqlConnection(...))
  24. using (SqlCommand command = connection.CreateCommand())
  25. {
  26. ...
  27. }
  28.  
  29. using (SqlConnection connection = new SqlConnection(FROM_CONFIGURATION))
  30. using (SqlCommand command = new SqlCommand("SomeSQL", connection))
  31. {
  32. connection.Open();
  33. command.ExecuteNonQuery();
  34. command.Dispose();
  35. connection.Dispose();
  36. }
Add Comment
Please, Sign In to add comment