samedi 25 avril 2015

Do multi-dimensional arrays eat memory and how do I free up their memory


I have a complex tableview. Objective C

To populate a number of labels in each cell I had a multi-dimension table composed of 2 NSMutableArrays (1 embedded inside the other). The result was an array that had 3 columns per row.

To free up memory I used [arrayname removeAllObjects];

Well all I can say is that this did absolutely nothing.

This array (which per row was only holding about 130 chars of data and in this sample data I only had 30 rows) was like a virus that's favourite food was memory. It ate chunks of 50mg like there was no tomorrow.

The removeAllObjects did nothing to recover memory.

I have searched high and low and find no clear way to free up memory when you are working with NSMutableArrays and it seems like multi-dimensional ones are cookie monsters.

In the end I removed the multi-dimensional array and just built a single NSMutableArray which was just all of the data concatenated into a string, which I then subStringed out the 3 pieces of data when I needed them.

Memory returned back to normal.

This may not have been the ideal solution. Has anyone found a clear way of releasing the memory of NSMutableArrays ?


Aucun commentaire:

Enregistrer un commentaire