genaray / Arch.Extended

Extensions for Arch with some useful features like Systems, Source Generator and Utils.
Apache License 2.0
152 stars 35 forks source link

World grows after deserialization #60

Open richdog opened 9 months ago

richdog commented 9 months ago

Every time I save the same world after loading, the world grows. This happens even if I save an empty world. This also happens with both Binary and JSON serialization.

I've attached two copies of the world JSON, once from the first save, and again after loading and saving again. note that it keeps growing every time I save and load, not just the first time.

world-empty-1.json world-empty-2.json

I tracked it to this point: image image

I dug a bit deeper after this and it seems to do with the way the capacity is calculated, and serialized. I attempted serializing/deserializing the capacity of just a single bucket instead of the total capacity, which seemed to partially fix the issue, but it would still grow in some cases so I moved on to other things.

ArhinZi commented 6 months ago

image

image

I found it. Firstly we set capacity in JaggedArray constructor. Then we EnsureCapacity and check newCapacity < Capacity (They are same by constructor) so it increases capacity again.. I think fix should be simple @genaray @richdog

Upd. I tried to remove world.EnsureCapacity(versions.Capacity); in serializer. It helped a bit, but still leaking.

genaray commented 5 months ago

Thanks! What do you think is the second leak problem?