nodemcu - Memory is not released after a dofile in lua -


i new lua , working on nodemcu. trying extract data xml file.

here xml file:

<?xml version="1.0" encoding="utf-8"?> <netconfig> <mode>0</mode> <stamac>18-fe-34-a4-4b-05</stamac> <staip>xxx.xxx.xxx.xxx</staip> <stanetmask>xxx.xxx.xxx.xxx</stanetmask> <stagateway>xxx.xxx.xxx.xxx</stagateway> <apmac>1a-fe-34-a4-4b-05</apmac> <apip>192.168.4.1</apip> <apnetmask>255.255.255.0</apnetmask> <apgateway>192.168.4.1</apgateway> <port>80</port> <dns>xxx.xxx.xxx.xxx</dns> <dhcp>1</dhcp> <stacustomconfig></stacustomconfig> <timezone>10</timezone> <serial>0x00000001</serial> <connssid>esp-10767109</connssid> <ssid></ssid> <passwd></passwd> <hostname>esp-10767109</hostname> <reboot></reboot> <message></message> </netconfig> 

here xmlparser:

return function (xmlfile, xmlword)     file.open(xmlfile,"r")     local eofflag = 0     local i, j, k, l, xmloutput     while(eofflag < 1)         local m = file.readline()         if(m == nil)             eofflag = eofflag + 1         elseif (string.find(m, xmlword) ~= nil)             i, j = string.find(m, xmlword, 1)             = - 1             j = j + 2             k, l = string.find(m, xmlword, j)             k = k - 3             l = l + 1             xmloutput = string.sub(m, j, k)             eoffile = 1         end     end     file.close()     return xmloutput end 

i call file using:

local port = dofile("xmlparser.lc")("netconfig.xml", "port") 

but endup memory less started though call garbagecollector. heap seems decrease further if word searching near end of file. observed if word looking not present, heap has less difference started with.

am missing something? , taking look.

alternatively, xml strictly settings/only used lua code? if found easier , less memory , compute intensive create settings file in lua syntax, , execute it. declare global table , exec file:

cfg = {}   dofile("settings.lua")   

and in settings.lua file assign members:

cfg.port = "80"   cfg.dhcp = "1"   cfg.mode = "0"    

you can write table file easily:

local buf = ""   mykey,myval in pairs(cfg)       buf = "cfg." .. mykey .. " = \"" .. myval .. "\""       file.writeline(buf)   end   

for it's worth...


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -