some question about memory management

Hello, i got a second question but since its quite a bit different than the previous one will post it here

1.)

function scene:create( event ) local sceneGroup = self.view

has its own group which is called sceneGroup, if i add all the display objects i use during my code they will niled and destroyed upon calling destroyScene

i make my own

sceneGroupStartingMenu = display.newGroup()  

and insert objects in it then add it to sceneGroup

sceneGroup:insert( sceneGroupStartingMenu ) 

then depending which button i press i do :removeSelf() and =nil on the group (and i quess when doing removeScene it kills anything that is left)

i remove listeners manually BUT i am not sure what to do with require functions

local composer = require( “composer” )
local composer = require( “json” )
local composer = require( “widget” )

should i leave composer as he gets called in another scene again? can i make it global and only call it once? i noticed if i remove json and widget upon being called again they get my memory usage HIGHER for some reason (for some small amount but it piles up, if i don’t do as it is said below i won’t get additional usages which leaves me confused…)
 

package.loaded["json"] = nil json=nil 

trying to optimize but so many problems so far and hope someone had similar problem/solution
 

2,) 

now i have a login scene with 2 input fields 2 buttons and 2 text variables

i am connecting to my own (local database thru network.request and php script) but once i enter my mainMenu chaos happens

from 244k memory it jumps to 370k and only thing inside is
 

local tableWidget = widget.newTableView {...}

am i correct in assuming that code below actually doesn’t remove it? because when i go back into previous menu 100k of memory is permanently used by something

tableWidget:removeSelf()
tableWidget=nil

are widgets removed differently?

3.) this might aswell be a bug but when i put tableWidget from the 2nd step into sceneGroup (from self.view) and then upon exiting the scene i ordered it to be deleted together with other objects inside

function logoutButton:touch( event ) if event.phase == "began" then      bgCreate:removeEventListener( "touch", bgCreate )     logoutButton:removeEventListener( "touch", logoutButton )     createButton:removeEventListener( "touch", createButton )         sceneGroupMainMenu:removeSelf()     sceneGroupMainMenu=nil     tableWidget:removeSelf()     tableWidget=nil     composer.gotoScene( "welcomeScreen", "slideLeft", 800 ) end return true end

the above code will work without error letting me go to some other scene BUT removing two red lines will produce an error

?:0: attempt to perform arithmetic on field 'contentHeight' (a nil value) stack traceback: ?: in function '\_manageRowLifeCycle' ?: in function \<?:524\> ?: in function \<?:221\>

my understanding of this is that if i don’t manually delete this widget, later when i remove the scene this error happens due to something (maybe it can’t access widgets properly or something)

just thought i would point it out as i am still not sure i properly “cleaned” this widget out of my system and if no one has any idea will prolly comment parts of code piece by piece until i find out

 

function scene:show( event ) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;local phase = event.phase &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if "did" == phase then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print( "1: show event, phase did" ) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- remove previous scene's view &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;composer.removeScene( "mainScreen" )

EDIT:

just went to test the theory and if i want to remove the widget with removeScene i gotta add widget library (which i suppose makes sense since its local and it can’t be deleted as easily)

but even having done that i am still losing ~100k somewhere with this widget (it doesn’t add up next time i go into the same scene btw so there is no “memory” leaks just this object that doesn’t move)

local widget = require( "widget" )&nbsp; -- remove previous scene's view composer.removeScene( "mainScreen")
  1. i just tested weirdest thing aswell so this confuses me even more so

THERE IS other code i just didn’t write it i was focusing on these lines here producing additional memory leaks and stuff
 

case1:
nothing

produces 260k of memory

case2:
local widget = require( “widget” )

produces 290k as it should since it uses its library

case3:
local widget = require( “widget” )
package.loaded[“widget”] = nil
widget=nil
produces 278k of memory AFTER being deleted

??? i mean if it cleared everything it should be 260k, so either i cleared it bad and have no idea what i am doing or i don’t understand it quite right yet so would like some explanation since i see it as a waste to clear it :smiley:

 

is there some way to see “what” is in the memory? thx for all the help! i know its plentiful read :smiley:

i commented the whole code and now without
tableMainScreen = widget.newTableView {…} i am having 1k leak compared to 60k with the table

tried to google but found nothing specific but what i found with “experimenting”

tableMainScreen:removeSelf()
tableMainScreen = nil 

doesn’t remove it just “hides” it or something

tableMainScreen:deleteAllRows() clears 10k out of 60k which means i need to manually delete 50k of something more and i really have no slightest idea of what :smiley:

my quess is this 

 

local function onRowRender( event ) &nbsp; &nbsp;local row = event.row &nbsp; &nbsp;local id = row.index &nbsp; &nbsp;local params = event.row.params &nbsp; &nbsp;row.bg = display.newRect( 0, 0, display.contentWidth, 60 ) &nbsp; &nbsp;row.bg.anchorX = 0 &nbsp; &nbsp;row.bg.anchorY = 0 &nbsp; &nbsp;row.bg:setFillColor( 1, 1, 1 ) &nbsp; &nbsp;row:insert( row.bg ) &nbsp; &nbsp;if ( event.row.params ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; row.imeText = display.newText( params.name, 12, 0, native.systemFontBold, 18 ) &nbsp; &nbsp; &nbsp; row.imeText.anchorX = 0 &nbsp; &nbsp; &nbsp; row.imeText.anchorY = 0.5 &nbsp; &nbsp; &nbsp; row.imeText:setFillColor( 0 ) &nbsp; &nbsp; &nbsp; row.imeText.y = 20 &nbsp; &nbsp; &nbsp; row.imeText.x = 42 &nbsp; &nbsp; &nbsp; row.kojaGrupaText = display.newText( params.kojaGrupa, 12, 0, native.systemFont, 18 ) &nbsp; &nbsp; &nbsp; row.kojaGrupaText.anchorX = 0 &nbsp; &nbsp; &nbsp; row.kojaGrupaText.anchorY = 0.5 &nbsp; &nbsp; &nbsp; row.kojaGrupaText:setFillColor( 0.5 ) &nbsp; &nbsp; &nbsp; row.kojaGrupaText.y = 40 &nbsp; &nbsp; &nbsp; row.kojaGrupaText.x = 42 if params.name=="jojo" then &nbsp; &nbsp; &nbsp; row.alertGrupe = display.newImageRect( "alert.png", 30 , 30, 40 ) &nbsp; &nbsp; &nbsp; row.alertGrupe.x = display.contentWidth - 40 &nbsp; &nbsp; &nbsp; row.alertGrupe.y = row.height / 2 end row.ikonicaGrupe = display.newImageRect( "Icon-Small@3x.png", 30 , 30, 40 ) &nbsp; &nbsp; &nbsp; row.ikonicaGrupe.x = 20 &nbsp; &nbsp; &nbsp; row.ikonicaGrupe.y = row.height / 2&nbsp; &nbsp; &nbsp; &nbsp; row:insert( row.imeText ) &nbsp; &nbsp; &nbsp; row:insert( row.kojaGrupaText ) &nbsp; &nbsp; &nbsp; row:insert( row.ikonicaGrupe ) &nbsp; if params.name=="jojo" then row:insert( row.alertGrupe ) end &nbsp; &nbsp;end &nbsp; &nbsp;return true end

i quessed he will automatically get rid of objects created here but seems not

if i put them into display group all elements disappear (turn invisible) and they don’t actually contribute to freeing any memory in the end so that is why i quessed it gets rid of itself automatically (with deletion of the rows)

i commented the whole code and now without
tableMainScreen = widget.newTableView {…} i am having 1k leak compared to 60k with the table

tried to google but found nothing specific but what i found with “experimenting”

tableMainScreen:removeSelf()
tableMainScreen = nil 

doesn’t remove it just “hides” it or something

tableMainScreen:deleteAllRows() clears 10k out of 60k which means i need to manually delete 50k of something more and i really have no slightest idea of what :smiley:

my quess is this 

 

local function onRowRender( event ) &nbsp; &nbsp;local row = event.row &nbsp; &nbsp;local id = row.index &nbsp; &nbsp;local params = event.row.params &nbsp; &nbsp;row.bg = display.newRect( 0, 0, display.contentWidth, 60 ) &nbsp; &nbsp;row.bg.anchorX = 0 &nbsp; &nbsp;row.bg.anchorY = 0 &nbsp; &nbsp;row.bg:setFillColor( 1, 1, 1 ) &nbsp; &nbsp;row:insert( row.bg ) &nbsp; &nbsp;if ( event.row.params ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; row.imeText = display.newText( params.name, 12, 0, native.systemFontBold, 18 ) &nbsp; &nbsp; &nbsp; row.imeText.anchorX = 0 &nbsp; &nbsp; &nbsp; row.imeText.anchorY = 0.5 &nbsp; &nbsp; &nbsp; row.imeText:setFillColor( 0 ) &nbsp; &nbsp; &nbsp; row.imeText.y = 20 &nbsp; &nbsp; &nbsp; row.imeText.x = 42 &nbsp; &nbsp; &nbsp; row.kojaGrupaText = display.newText( params.kojaGrupa, 12, 0, native.systemFont, 18 ) &nbsp; &nbsp; &nbsp; row.kojaGrupaText.anchorX = 0 &nbsp; &nbsp; &nbsp; row.kojaGrupaText.anchorY = 0.5 &nbsp; &nbsp; &nbsp; row.kojaGrupaText:setFillColor( 0.5 ) &nbsp; &nbsp; &nbsp; row.kojaGrupaText.y = 40 &nbsp; &nbsp; &nbsp; row.kojaGrupaText.x = 42 if params.name=="jojo" then &nbsp; &nbsp; &nbsp; row.alertGrupe = display.newImageRect( "alert.png", 30 , 30, 40 ) &nbsp; &nbsp; &nbsp; row.alertGrupe.x = display.contentWidth - 40 &nbsp; &nbsp; &nbsp; row.alertGrupe.y = row.height / 2 end row.ikonicaGrupe = display.newImageRect( "Icon-Small@3x.png", 30 , 30, 40 ) &nbsp; &nbsp; &nbsp; row.ikonicaGrupe.x = 20 &nbsp; &nbsp; &nbsp; row.ikonicaGrupe.y = row.height / 2&nbsp; &nbsp; &nbsp; &nbsp; row:insert( row.imeText ) &nbsp; &nbsp; &nbsp; row:insert( row.kojaGrupaText ) &nbsp; &nbsp; &nbsp; row:insert( row.ikonicaGrupe ) &nbsp; if params.name=="jojo" then row:insert( row.alertGrupe ) end &nbsp; &nbsp;end &nbsp; &nbsp;return true end

i quessed he will automatically get rid of objects created here but seems not

if i put them into display group all elements disappear (turn invisible) and they don’t actually contribute to freeing any memory in the end so that is why i quessed it gets rid of itself automatically (with deletion of the rows)