|
devvvy wrote: to point#2 whhy you said I'm wrong?
I'm just saying you have no control over when managed resources are released.
Implementing IDisposable does not change that...IDisposable is meant for
unmanaged resources.
I got the feeling from your post that you felt IDisposable would give
you some kind of deterministic cleanup of managed resources, which is
not the case
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
|
Aren't we being a little pedantic here?
Consider a class like this
class Foo
{
StreamReader reader;
IntPtr handle;
public Foo()
{
}
}
Now I would dispose the StreamReader and close the IntPtr handle inside Dispose(true), but will only close the handle inside Dispose(false).
I guess it boils down to whether you consider StreamReader to be a managed resource, or a managed wrapper over an unmanaged resource. I would say it is a managed resource, given that it has a Dispose/Close and a finalizer.
|
|
|
|
|
S. Senthil Kumar wrote: Aren't we being a little pedantic here?
I suppose to you, yes, but I didn't reply to you.
Sure, you often need to know if your managed objects hold unmanaged resources and free
those resources as deterministically as you can if you need to....but still,
calling a class' Dispose doesn't mean you've freed the managed object, which was my point
to devvy.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
devvvy wrote: Managed memory is freed by call to Dispose
No. This is the main difference for a memory management system that has a garbage collector: It's the garbage collection that frees all managed memory, that can not be done any other way. The garbage collector removes any objects that has no references to it, so to get an object collected you just make sure that there is no reference to it.
If an object has no references to it, the references that it contains are not considered as active by the garbage collector. Therefore, if an ojbect only references managed objects (that don't implement IDisposable), you don't have to do anything at all when releasing the object. At the moment when the object is up for garbage collection, all it's child objects are automatically up for garbage collection (unless they are also referenced from some other object).
There is no destructor in C#, like there is in C++. There is no reference counting going on, so at the moment when you remove the last reference to an object, nothing happens. When the garbage collector notices that the object can be collected, but it has a finalizer method (that uses the same syntax as a destructor in C++), the object placed in the finalizing queue. A background thread is working the queue, calling the finalizer method of each object, and after that the object is a regular managed object that the garbage collector can remove.
The finalizer method is only used as a backup for when the Dispose method is not called properly. The Dispose method is the normal means of controlling the life cycle of an object.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
... i think I mentioned "managed resource" (not memory) freed by Dispose.
dev
|
|
|
|
|
Perhaps once you did, but that's not what was in the question when I read it. I marked the text in the question and pressed the "Quote Selected Text" button, so it's an exact quote from the question.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hello,
I have 2 forms in my application (form1-the main, form2). How can i use in form2 methods that i wrote in
|
|
|
|
|
Assuming you are in Form1 and your other form is called Form2:
If the method in Form2 is static:
Form2.UseMethod();
If the method in Form2 is non-static:
Form2 f = new Form2();
f.UseMethod();
OK?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
When do i need to use static methods and when non-static?
|
|
|
|
|
Oh Boy!
This is a bit fundamental, so I'll try to explain, but it is probably better explained in any of the many books on C# out there.
You can use a static method at any time: String.Format(...) is a static method. You give it as a command:
string s = String.Format("The result is {0}", 6 * 9);
and it evaluates to a string "The result is 54".
You use a non-static method when you want it work on an object: an instance of the class.
class Example
{
public string data;
public int CountChars()
{
return data.Length;
}
}
...
Example ex = new Example();
ex.data = "ABCDEFGHIJKLM";
int i = ex.CountChars();
...
ex is an instance of the Example class, so you can call CountChars on ex, and it will work on the data that is relevant to ex only. If you declare another variable ex2, then ex.CountChars() and ex2.CountChars() will return different values, depending on what data you have fed them.
Static methods can only access static data (and other static methods). In the Example class, you cannot define a static method that can access the "data" string, because it is non-static.
Does that make sense?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Why dont you write a new Class(lets say Common) and write your method there.
You can call this method from both form1 and form2
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Ok, But why it will be good to do it? Or at all to write with classes ( i mean for example if i have only one form)?
|
|
|
|
|
A form IS a class.
And he's right. If you're going to have methods that you need to call from multiple forms, then the logic place to put those methods would be the class that stores the data that your app is manipulating.
|
|
|
|
|
Currently I am downloading exchange data and using DataGridView to display the data in real time.
I have as many as 6 DataGrids with 5 columns and many rows each that are updated about twice a second. The problem is, if only a few cells are modified, most of the time the whole grid is repainted degrading the performance of the DataGrid! I know this to be the case as some flicker is evident on cells that are unchanged. I have also implemented a simple counter in the CellPainting event to verify this.
Does anybody know how to only paint cells that have changed and bypass the others?
john1166
|
|
|
|
|
I Created C# Program and add FREngin and FineReader Components. Can I Create default Textblock using block in the same project
|
|
|
|
|
? Can I see how have you done that ?
|
|
|
|
|
Can you please share the code with me.....i am searching for the same from long....not unable to get the information on google.
or you can suggest any site wherein i'll get the code
|
|
|
|
|
Is that possible to draw a graph by getting the values from database in windows application
|
|
|
|
|
|
|
I don't pretend to be a .NET expert, but I saw a query that the OP could have got an answer to by doing a painfully obvious search. Had to vent it out.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
hello
i have acrystalreport wich is conect to dataset
i have ther textboxes in section 1 and in section 4
i want to change the text of these textboxe by acode in run time
thanks
|
|
|
|
|
this.BackColor = colorDialog1.Color;
The main Form disapears and I have to go into the control bar at the bottom to find it.
How do I use ToolTip after I placed one onto the form as a non-visual component? How do I link it to a component & choose the text on the tip?
|
|
|
|