[Issue 16824] std.experimental.allocator.dispose leaks memory for arrays of more than 1 dimension

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Dec 23 08:54:39 PST 2016


https://issues.dlang.org/show_bug.cgi?id=16824

--- Comment #6 from Andrei Alexandrescu <andrei at erdani.com> ---
(In reply to Atila Neves from comment #5)
> I understand the arguments; but I still think there should be an easy,
> canonical way of allocating arrays of more than one dimension and be able to
> dispose of them without leaking memory. I didn't even know I _was_ leaking
> memory until I wrote that test allocator. And I only did _that_ because I'm
> paranoid.

It seems the right view is this:

* If you used a loop to allocate your multidimensional array, you're supposed
to use a loop to deallocate your multidimensional array. The library can't
guess what you did.
* If the library provides a means to dispose a multidimensional array in one
shot under certain assumptions, the library must provide a means to create a
multidimensional array in one shot such that those assumptions are fulfilled.

One way I see this moving forward is to provide the following functions:

* makeMultidimensional -> does the looparoo that Atila currently does by hand
* disposeMultidimensional -> does what Razvan does now in his PR, i.e. disposes
the whole array ASSUMING it had been created by makeMultidimensional

(maybe later)

* makeCompactMultidimensional -> computes the appopriate sizes and allocates
one hunk that is then sliced and diced to return the multidimensional array.
* disposeCompactMultidimensional -> disposes an array ASSUMING it had been
created by makeCompactMultidimensional

--


More information about the Digitalmars-d-bugs mailing list