I am still working on this virtual container :) but rather than create and return a view now, I create a cell class that inherits from ui.View.
Basically the same thing, just more flexible. But because it's a virtual container, it's important I clean up all the memory.
I am not using __del__ because from what I read this is unreliable and prone to errors with creating circular references etc. There seems to be a work around with weakrefs, but for what I need, I can call a method on the cell object explicitly to do the clean up.
So when I want to delete the cell object , I do the following:
First I call a release method. This is where I should clean up. I am just not sure what to clean up :(
All I do currently is use the cell objects superview to remove itself from the superviews subviews.
In this case, I also have an ImageView with a loaded image from disk/memory. It has been loaded with ui.Image.named method. Should I also be releasing this resource also somehow. Also what if I had a button with a background image loaded? Should I explicitly be unloading these resources? What about subviews of the cell object, if I have created them. Should I also be removing them from the cell object view? Just asking!
After calling the release method on the cell object, I then call del cell.
I understand this is pretty open question, but I don't think I can get these answers in a general python forum.
I think for the most part they are trivial issues in most apps , but when you are creating many thousands of views and then destroying them again, huge potential for a very bad memory leak.
Any help appreciated. Also any ideas about how to measure a memory leak. I really have no idea how to do this in this day and age. Was easy in the old days :) I realise these days it's a complicated issue. At the moment, I am just tracking the number of subviews in the scrollview not much else. Thanks in advance.