Câu hỏi phỏng vấn C#
Câu hỏi

You have defined a destructor in a class that you have devel...

Câu trả lời

Here are a few possible reasons why a C# destructor (finalizer) may not execute:

Garbage Collection

The .NET garbage collector is responsible for automatically reclaiming memory occupied by objects that are no longer in use. However, the garbage collector does not guarantee when a destructor will be called. It will only call a destructor when the object is eligible for collection and the garbage collector decides to collect it.

Explicit Disposal

If the object implements IDisposable and the Dispose() method is called, the destructor will not be called. The Dispose() method should be used to release unmanaged resources, while the destructor is intended for cleaning up managed resources. Calling Dispose() explicitly will prevent the destructor from executing.

Circular References

If an object has a circular reference to another object, the garbage collector may not be able to determine that the object is no lon...

expert

expert

Gợi ý câu hỏi phỏng vấn

senior

Is operator overloading supported in C#?

junior

What are Nullable types in C#?

junior

What is enum in C#?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào