Answer the question
In order to leave comments, you need to log in
How are objects destroyed and do we need to destroy them ourselves?
Here is a sample code.
public static string GetLastFolderName(string filePath)
{
FileInfo fileInfo = new FileInfo(filePath);
return fileInfo.Directory.Name;
}
Answer the question
In order to leave comments, you need to log in
CLRium #5: Garbage Collector. 2019
Expands understanding of how GC works, memory allocation and usage, etc. But without first reading the relevant material, for example, from Richter, it will be difficult to understand.
How does the .NET VM know when it's time to destroy an object? And when does it happen?
What happens if you need to execute the code above in a loop? That is, many objects will be created.
I don't think I need them anymore. As soon as I got return (folder name), I don't need this object.
And if all this is in a cycle, it would be logical to immediately destroy the object.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question