Removing methods calls off the stack in C#
how can remove method calls off stack of object in c#?
i set variable equal null object still executing code.
for example if have onc class calling method of other , calling other methods in class this:
class a { private b var; void start() { var = new b; var.runflag true; var.run(); } void stop() { var.runflag = false; var.dispse(); var = null; } } class b : idisposable { public bool runflag = false; void run() { while(runflag) { meth1(); meth2(); meth3(); } } void meth1() { dosomething(); } void meth2() { dosomething(); } void meth3() { dosomething(); } void dosomething() { return; } void dispose() { // clean resources } } |
then after call in stop() method of class a, b should garabage collected no matter control of execution is. right or wrong.
please help!!!!!!!!!!!!!!!!!!!!!!!!
i think i need explain you. removing object off stack can done, not "forcing" gc pull off, "asking" it. now, if gc determines right time pull object off, biding, if has not, won't it. gc knowing, omni-present, greater-being. can , ask, cannot command.
example:
using system;
namespace unmanagedresourceobjlib ~ownsunmanagedresources() void cleanup() public void close() #region idisposable members bool _disposed = false; #endregion public void someotheroperation()
|
using system; namespace funwithgc // obj.dispose(); static void main()
|
reference unmanagedresourceobject funwithgc. understand how gc destroys object , takes off stack.
Archived Forums V > Visual C# Language
Comments
Post a Comment