c# - How to Clear() controls without causing a memory leak -
after reading control.clear();
causing memory leaks (verified @ msdn), wondering if:
while (controls.count > 0) controls[0].dispose();
will enough, or have iterate recursively through controls within controls?
also, there reason control.clear();
after that? (as saw saying somewhere)?
thanks.
the posted snippet correct. no clear() required, control.dispose() method removes control controls collection. why works.
the less alarming version of loop is:
(int ix = controls.count-1; ix >= 0; --ix) controls[ix].dispose();
no need iterate through children of control , dispose them, happens automatically.
Comments
Post a Comment