0

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.

Vakho
  • 87
  • 7
  • Does memory usage go up every time the window is expanded? Do you remove the data from unused cells? – Willeke Jun 30 '19 at 08:34
  • 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 Jun 30 '19 at 08:48
  • Do you remove the images and texts from the cell views when they go to the reuse queue? – Willeke Jun 30 '19 at 11:50
  • 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 Jun 30 '19 at 13:20
  • Did you use Instruments to investigate? – Willeke Jul 01 '19 at 13:16
  • Yes I tried, but gave up ultimately and swapped out half our my View-Based Table Cells to Cell-Based ones. As I have looked up on multiple forums (link in post), Cell-based table yield a better performance. As my app has a huge database, it makes more sense to use as simple table structure as possible. No it's clear to me why most macOS system Tables (finder, iTunes, etc...) look so simple. Loading large data in View-Based Table cripples performance. But again, why is Apple deprecating Cell-Based Tables in favor for View-Based ones, when Cell-s still have some good use? Whatever... – Vakho Jul 02 '19 at 06:34

0 Answers0