Open dktapps opened 5 years ago
Sadly ext-ds
is not a solution to this problem because its behaviour when modifying a datastructure during iteration is undefined, leading to bugs.
To memory, the only major place where this bug might have a significant is in World->chunks
, and a specific workaround for that might be OK. Almost all other long-life arrays in PM code don't have large variations in size.
Issue description
PHP "arrays" do not release memory when
unset()
ing elements from them, ever. This is problematic for long-life arrays in a long-life program like PocketMine-MP because memory allocated in, for example, the levelchunks
array will never be released.The below code can be used to verify the problem.
This appears to be an artifact of the internal
array
implementation. It makes sense in a web server environment, but not in a CLI program.Possible solutions
Ds\Map
object releases memory when the allocated slots drop below 1/4 of the capacity. This could have adverse side effects on performance in a loop like this one due to repeated reallocations, so this needs to be carefully handled. (In the script above, replacing the array with aMap
frees the memory appropriately, but is 60% slower).