Home > Net > Foreign transfer function through the out keyword list parameters involved in memory release and lif
Foreign transfer function through the out keyword list parameters involved in memory release and lif
Time:11-23
Foreign transfer list 1 by 1, way out parameter list
public bool getRedIR (string file, out List Red, out List Ir) { FileStream fs=new FileStream (file, FileMode. Open);
StreamReader sr=new StreamReader (fs);
String STR="";
Red=new List (a); Ir=new List (a);
Do { STR=sr. ReadLine ();
String [] strArray=STR. The Split (' '). The Where (x=& gt; ! String. IsNullOrEmpty (x)). ToArray ();
Double vRed=double. Parse (strArray [2]).
Double vIr=double. Parse (strArray [3]).
Red. The Add (vRed);
Ir. The Add (vIr); } While (STR!=null);
return true; }
Double vRed=double. Parse (strArray [2]).
Double vIr=double. Parse (strArray [3]).
This way, each call, we do have a new, will lead to a memory leak? If you remove the list is done automatically by c #, will the external call function in the gain List after red and ir, the internal data has not been processed and will be released automatically by c #? Will there be this kind of situation,
Method 2: through ref foreign ginseng But outside the new two global List, this should not have what problem
CodePudding user response:
C # memory release not so fast, don't worry about finished processing the data were released, https://www.cnblogs.com/worfdream/articles/2345053.html
CodePudding user response:
Reference data exist, would not be recycled,
CodePudding user response:
Will not lead to a memory leak? __gc can recycle, you as long as don't kill cycle out end recycling List after red and ir, the internal data has not been processed and will be released automatically by c #? As long as you don't manual recovery will not, you have to wait for automatic recovery methods performed
But outside the new two global List, this should not have what problem, this is a global variable that you? Use of global variables in use after the empty can, what all have no problem