You used a mgr. Dispose call in the second example. I'll take it mgr is an IDisposable?
You used a mgr. Dispose call in the second example. I'll take it mgr is an IDisposable?
In that case, you need to use a using block: for (int I = 0; I.
Good suggestion. I failed to remember the using statement, which does the same as my code above, except the call to Dispose() is created via compiler rather than in my code, right? +1 for optimizing my pseudo code.
However, in my production environment, the Snmpmgr is a global var in the Page class (since it is used multiple times via button click events, and load events), so I don't really have the option to Dispose directly after use (unless I want to recreate the object on 15 different occasions). Sorry I did not mention that in my original post. – regex Jul 8 '09 at 1:58 1 A using block in not needed.It's probably a good idea, but it's not necessary.
Calling Dispose will accomplish the same thing, though the call to Dispose should probably be in a finally block. – Todd Ropog Jul 8 '09 at 1:59 3 If you don't want to dispose of the object after each use, then you need to make sure it gets disposed of at some point. If there's a reliable point at which you can do this then that would work.
However, it's generally a recommended practice to dispose of things as soon as it makes sense to do so. So make sure you aren't holding on to the object longer than you should. Think carefully about this.
– Todd Ropog Jul 8 '09 at 2:03 I presume I will call the Dispose() at the end of the Page's life cycle then... Argh... I can never remember the Page's final event off hand... unload maybe? Anyway, off to Google :) Thanks for all the tips. I will look into creating a new object every time I want to use that function since everyone seems to recommend that is better practice.
– regex Jul 8 '09 at 2:10.
That's the point about the Dipose() method. Since one can never know when the destructor will be called, you should use Dispose to release unmanaged resources. As MiffTheFox said, you should put your code inside an 'using' block.
When the code execution reaches the end of the 'using' block, Dipose() will be called automatically.
Calling Dispose is the proper thing to do. Some objects use unmanaged resources (and if you're working with sockets, it's likely the case). The Dispose method is exposed precisely so that the object can properly deallocate its unmanaged resources.
Any time you use an object that implements IDisposable, you should call Dispose when you're done with it. For more detail about IDisposable: stackoverflow.com/questions/12368/how-to....
Perhaps you can put mgr.Dispose() in your "finally" clause, after your try/catch block.
... otherwise the GC does not know there is some work to be done to release resources if you do not do it explicitly through Dispose().
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.