开发者

Java initialize question

开发者 https://www.devze.com 2023-02-03 07:31 出处:网络
What does the below code do whe开发者_高级运维n you instantiate the StudentRegistrar class? public class StudentRegistrar

What does the below code do whe开发者_高级运维n you instantiate the StudentRegistrar class?

public class StudentRegistrar
{
    public StudentRegistrar ();
    {
        new RecordManager().Initialize();
    }
}


It doesn't necessary destroy the RecordManager immediately. Initialize() may spawn a new thread which can then hold a reference to the RecordManager. Since new threads are a garbage collection root, the RecordManager reference will be reachable from that root and therefore it will not be cleaned up.

It really depends on what Initialize does!


It creates an instance of RecordManager, calls the Initialize() method and then destroys the instance of RecordManager.

EDIT: Actually it won't compile due to the spurious ;

0

精彩评论

暂无评论...
验证码 换一张
取 消