Reply To: Memory leak or not ?

Why OSVVM™? Forums VHDL Memory leak or not ? Reply To: Memory leak or not ?


Hi Jim,
Thank you for your elaborate (and much appreciated) reply.
It is very useful and confirms what I feared being the case: that this is in fact a memory leak…
The first solution you suggest was actually already on my mind as a working alternative (without the memory leak). But this approach has the side-effect that an additional ‘copy object’ is created before returning from the function, which is unfortunate and inefficient if we are talking about LARGE objects…
So I was – naively – assuming/hoping that the compiler would be ‘smart’ enough to know that in the specific case that a function is returning the contents of a – locally declared – pointer object (and not the pointer object itself), it should become responsible for managing that allocated memory, as there is no way for the caller of this function to be able to do this…

Kind regards,