oop - Explain what happened in following code in c# -


is creates 1000 person objects?

public class person {    public string firstname;      public string lastname;     }  person person;     for(int = 0; < 1000; i++) {     person = new person(); } 

the code creates 1000 person objects, keeps reference last-created one. others exist in memory while, unreferenced , unusable , therefore @ point reclaimed garbage collector.

(to precise, code given doesn't tell how long last reference alive. if person not referenced @ point other code given, become eligible collection after loop , collected @ time thereafter.)


Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -