My question is about memory management. I am looking for ways to release all AQGridViewCell items that belong to AQGridView. This is to recover memory when I switch to a different view because each cell has large image). For some reason, releasing the AQGridView itself doesn't release the cells. I tried this bit of code as alternative but the error message below is posted:
NSIndexSet *visibleIndices = [gridView visibleCellIndices];
[gridView beginUpdates];
[gridView deleteItemsAtIndices:visibleIndices withAnimation:AQGridViewItemAnimationNone];
[gridView endUpdates];
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid number of items in AQGridView: Started with 6, added 0, deleted 6. Expected 0 items after changes, but got 6'
Could you help me what I am missing to properly remove the cells from grid view? Also, is there a smart way to release the memory that grid view occupies all together?
Thanks
First part about deleting cells: The grid view only keeps track of them via -addSubview: and the visibleCells and reusableGridCells member variables. If you remove the grid view from its hierarchy and release any references to it that you hold, then it absolutely will delete all its cells.
As to the second part, the issue is that (in an effort to mimic UITableView’s behaviour) AQGridView will check with its data source to verify that the data source’s information matches what it’s figured out from all the deletions and insertions it’s just handled. In your case, your data source is still telling it that it has six objects (via the -numberOfItemsInGridView: method).
The correct method to release everything the grid view has is to release any references you hold to it and to remove it from the view hierarchy. That definitely does the trick— I’ve seen it working in the Kobo app just last week.