So I was just reading about the RAII pattern for non garbage collected languages, and this section caught my eye:
This limitation is typically encountered whenever developing custom classes. Custom classes in C# and Java have to explicitly implement the dispose method in order to be dispose-compatible for the client code. The dispose method has to contain explicit closing of all child resources belonging to the class. This limitation does not exist in C++ with RAII, where the destructor of custom classes automatically destructs all child resources recursively without requiring any explicit code.
Why is it that C++ can correctly track these resources that are allocated in the RAII pattern, but we don't get this lovely Stack Unwinding with the C# using construct?
delete
them all manually? How do you handle aList<Stream>
in C#? You close (orusing
) them all manually? Seems quite similar to me. How do you handle a class that has aList<Stream>
member? – Secretion