Fix a bug in -[freeMemory:].

This could be an out of bounds write if the last element is free'd,
as i is pointing to the last element then, which does not exist then
anymore, as it was already resized. Now, it is set before resizing.

Additionally, if the realloc to make it smaller fails, we just ignore
that now - it will still work, as we set the correct size before
resizing.