Can I have some kind of a memory leak when an exception is being thrown?

For example, suppose I have a struct with some array variables, and I read data in it from a file, variable by variable. What if I throw a custom exception (without catching) after unsuccessful attempt of reading the third array, asking a user to check the data in the file, for instance? Will the data of the first two arrays (and possibly other instantiated objects) be safely released? Should I worry about performance or memory consumption issues, or are there none of such?

Yes. The garbage collector will at some point handle that.

Allocating a huge amount of “unnecessary” memory will of course have performance considerations but that doesn’t seem to apply to this case.

1 Like

@kristoffer.carlsson This answer satisfies me, thank you.