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

CodePudding user response:

The
reference rabbit family - second brother reply: 3/f
will 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


1, automatic recovery until the method is performed, but the method after a long period of time, two red and ir out list will be used by external,
C # will automatically determine the two list after use to release, or is it just in getRedIR immediately release method has been completed

2, the global list, such as the new out of the list in the constructor, c # does not automatically release, require developers manual release, is this meaning?

CodePudding user response:

As long as there is a reference, I would not be recycled, it is managed object is a simple and practical management principle, as long as the object you use, also will not be recycled, no need to worry about the problem of recycling in advance, but sometimes have to worry about recovery fast enough, so in the net inside need unmanaged objects,

Out, ref, return, is a kind of reference, reference chain has been beyond the function body, the operation of the function over, has no effect on these objects are completely,

CodePudding user response:

refer to fifth floor closure guest response:
as long as there is a reference, and will not be recycled, is managed object is a simple and practical management principle, as long as the object you use, also will not be recycled, no need to worry about the problem of recycling in advance, but sometimes have to worry about recovery fast enough, so in the net inside need unmanaged objects,

Out, ref, return, is a kind of reference, reference chain has been beyond the function body, the operation of the function over, has no effect on these objects are completely,


Oh I see, here is not like c, c + + to do memory recovery, the system automatically help fixed,

Here's another question need to ask for leave:
Is you of the above said recovered quickly enough, such as a serial analytic function, there is a new list of actions, if frequent accept to frame a serial port and will have frequent calls to the new list, if the system recovered quickly enough, can cause what influence, such as memory leaks, parsing caton

CodePudding user response:

Out of memory, directly when the summer

CodePudding user response:

C # List Is managed object, there is no way to manually release resources managed object, don't know your List Length is how many, how much memory generally cannot be accounted for, you should believe managed object. The net will be recycling of resources in a timely manner,

There is no way to timely collection objects, the.net became unmanaged are designed, such as images, related to flow, in fact this is a kind of helpless, because there is no way to timely recovery, so the recovery of permissions to the programmers, these objects will have a the Dispose method, let the programmers to take the initiative to call in for recycling,

Managed language including unmanaged objects, which actually cause a lot of trouble to programming, especially the start learning managed language programmers, but this is managed language technology ceiling, don't know when can solve this problem, make all objects into a managed,

If you want to know about the timing of the recycling, recycling machine, you can write a class with a destructor, recycling machine recycling object, the destructor will call this, if the destructor do inside the tip or log, so you'll know when to release the object's resources recycling machine,

CodePudding user response:

refer to 6th floor number007cool response:
Quote: refer to fifth floor closure guest response:

As long as there is a reference, I would not be recycled, it is managed object is a simple and practical management principle, as long as the object you use, also will not be recycled, no need to worry about the problem of recycling in advance, but sometimes have to worry about recovery fast enough, so in the net inside need unmanaged objects,

Out, ref, return, is a kind of reference, reference chain has been beyond the function body, the operation of the function over, has no effect on these objects are completely,


Oh I see, here is not like c, c + + to do memory recovery, the system automatically help fixed,

Here's another question need to ask for leave:
Is you of the above said recovered quickly enough, such as a serial analytic function, there is a new list of actions, if frequent accept to frame a serial port and will have frequent calls to the new list, if the system recovered quickly enough, can cause what influence, such as memory leaks, parsing caton


Although the object reference is "fast enough" call GC after release, but also call at least once a few seconds, so you don't have to worry about,
  •  Tags:  
  • C#
  • Related