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

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -