I have a function call where i create an ArrayList(u8) but I don't defer list.deinit() because I want to return an owned ArrayList to the caller function. The reason, acc. to my understanding is if I do return a slice i.e. []const u8 and call defer list.deinit() then my slice will point to invalid or freed memory which is rarely what anyone wants.
So searching around I found toOwnedSlice which seems like it does what I want that is return an []u8 but it clears or empties the arraylist? I don't understand this comment, does calling this method free the array list? If so then what is the returned slice a view of?