c# - Does a list clear delete the objects previously contained -
imagining have :
list<myobject> mylist = new list<myobject>(); myobject obj1 = new myobject(); myobject obj2 = new myobject(); mylist.add(obj1); mylist.add(obj2); does a
mylist.clear(); delete instantiated : 'obj1','obj2' ? or kept in memory list empty ?
as far have reference object , can access in code there in memory , garbage collector not collecting it. reply no, kept in memory
you can read more garbage collection here.
if code this
list<myobject> mylist = new list<myobject>(); mylist.add(new myobject()); mylist.add(new myobject()); then when phone call mylist.clear() have no reference created myobjects garbage collector collect them , delete them memory in it's next run. if want remove obj1 , obj2 memory after clearing list should utilize
obj1 = null; obj2 = null; gc.collect() but aware of consequences of forcing garbage collection.
c# .net list
No comments:
Post a Comment