0
votes

In my Cocoa project I have a button set up, that when pressed, expands the window frame downwards to reveal a Container View, that has a Table View inside. I load various data (images, texts, etc..) from computer to memory where it stays until app quits. Data gets passed to Table View for displaying when button is pressed and view becomes visible.

I first created Cell-Based NSTableView. When window is collapsed (i.e., not showing Container View with its Table View), memory usage in XCode is only 80 MB. When I expand the window, it jumps to 160 MB (which is normal). If I collapse the window back, memory usage drops to 80 MB, with no memory leak.

Then I opted for more customization and changed Cell-Based NSTableView to View-Based NSTableView. I have loaded same data, but I started to have memory issues. When window was collapsed, I still had 80 MB of memory usage, but when expanded, it all of a sudden jumps to 260 MB+. I assumed this was due to Cell-Based NSTableView being more lightweight that View-Based one, which was fine with me. However, when I collapse the window, the memory usage drops to mere 240 MB, when compared to Cell-Based's 80 MB.

I have tried to track down issue many ways. I emptied the datasource from which the TableView loads, and have forced reloadData() on it, but it doesn't seem to clear memory issues.

There is no information about it on the internet or Apple docs, as it seems. Closest I have found was this (not the comment, the sub comment), which said that "Cell-Based NSTableView is a visual template and stores no data on it's own".

Am I doing something wrong? Any help would be appreciated.

Does memory usage go up every time the window is expanded? Do you remove the data from unused cells?Willeke
In case of Cell-Based, the collapsed memory usage is 80 MB, and it increases to 160 when expanded; and decreases to 80 MB when collapsed again. This is normal. View-Based however doesn't return to 80 MB when collapsed. Yes, I remove data from unused cells. In my viewDidDissapear() lifecycle function, I zero the database, and do reloadData(), so that now cells only would store empty data.Vakho
Do you remove the images and texts from the cell views when they go to the reuse queue?Willeke
That seems to be an issue. I removed images all-together from my cells to test it. Since images are much more heavy-weight than text fields, memory leak decreased significantly. And I noticed that over time, text fields very creating minor leaks (5 MB). Seems that I have some serious issues with reusing, which I never faced with Cell-Based views.Vakho
Did you use Instruments to investigate?Willeke