fix: initialise/deinitialise of (boxed) array data#8
Merged
Conversation
6df25b1 to
318551a
Compare
JaapWijnen
reviewed
Dec 15, 2025
c063740 to
a3dfc67
Compare
JaapWijnen
reviewed
Dec 15, 2025
| public protocol ArrayData { | ||
| associatedtype Buffer | ||
|
|
||
| static func initialise(_ arrayData: Buffer, at: Int, to value: Self) |
There was a problem hiding this comment.
Let's add a comment here that describes what these are expected to do
JaapWijnen
reviewed
Dec 15, 2025
JaapWijnen
approved these changes
Dec 15, 2025
Storage is variable sized (depending on the element type) so having the count and context pointer fields at the start of the object gives a fixed a offset to (the start of) all fields.
This also drops the inout qualifier on the Buffer parameter, which is not needed (the buffer contents may change, but not the pointer to the buffer itself).
This is required for any class-based types (e.g. String) that we are storing via Box. When first writing to the raw buffer we must initialise the memory (retaining as strong reference to the value that is not owned by us) and ensure that memory is deinitialised when the containing MultiArray is deallocated (releasing said strong reference). Previously we were not doing the latter, and when modifying elements (subscript write) re-initialising that slot. Both of these would cause memory leaks.
a3dfc67 to
f4fbfb0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is required for any class-based types (e.g. String) that we are storing via
Box. When first writing to the raw buffer we must initialise the memory (retaining as strong reference to the value that is not owned by us) and ensure that memory is deinitialised when the containing MultiArray is deallocated (releasing said strong reference). Previously we were not doing the latter, and when modifying elements (subscript write) re-initialising that slot. Both of these would cause memory leaks.