Home > Net >  C # example destruction
C # example destruction

Time:04-24

Small white:

I'm form1 defines a global type variable
Public class A {}
The public A, b.

Then in the process a few times to use

B=new A (); -> Load an a file


Once again behind

B=new A (); -> Loading a file b

By this time, the above instance is A system automatic recovery? In the

CodePudding user response:

Recycling is to the operation of the object, not to the operation of the class, b=new A (); Perform 2 times, in b not yet, recycling?

When b=null, can be recycled, b and c # has its own recovery mechanism, although you can manually System. GC. Collect (); With bad it will make the program runs more slowly,

CodePudding user response:

Concrete is the case, I have a list In DGV, T is stored in a different path to the file
I define A publc A CurrentObject,

The selected List line 3, I use CurrentObject=new A (); To perform different operations,

Then I click on the 5 rows, also want to use CurrentObject=new A (); Is the second,

So the last 3 lines of new A () object will be destroyed?

I click on the back to 3 lines, will regenerate again,

CodePudding user response:

refer to the second floor tucker heather's reply:
specific, so I have a list In DGV, T is stored in a different path to the file
I define A publc A CurrentObject,

The selected List line 3, I use CurrentObject=new A (); To perform different operations,

Then I click on the 5 rows, also want to use CurrentObject=new A (); Is the second,

So the last 3 lines of new A () object will be destroyed?

I click on the back to 3 lines, will again to regenerate,
should be can, because there are no quotes, but when recycling, decide by the system,

CodePudding user response:

Has not been referenced objects, the system will recycling, but when recycling can't guarantee anything, b=new A () again, b the original reference object is cited no longer

CodePudding user response:

The
reference
has not been referenced objects


So I don't answer is not destroyed, this need your own answer, you have no other place on earth to take up his, not to take up the Gc will include the release, have occupied the Gc which dare disorderly to release
  •  Tags:  
  • C#
  • Related