-->
Page 1 of 2

Out of memory but heap shows about 5kb available

PostPosted: Wed Apr 08, 2015 8:08 pm
by pit
Hi,
I run this simple loop dumping lua memory usage and heap while filling an array with objects - very easy reproducible.
Why though does it run out of memory while still having about 5kb heap available? I'd have expected it to break at under 100 since each newly created object added to the collection uses only 48 bytes.

Any idea? Is this a bug?

Code: Select all> a={} for i=1,1000 do print(i,collectgarbage('count'),node.heap()) a[i]={} tmr.wdclr() end
1       5.2666015625    21664
2       5.3447265625    21528
3       5.3759765625    21480
...
256     17.2666015625   5056
257     17.2978515625   5008
258     17.3291015625   4960
not enough memory


pit

Re: Out of memory but heap shows about 5kb available

PostPosted: Thu Apr 09, 2015 3:49 pm
by cal
Moin,

nice example.

Look here:
Code: Select alla={} h2=0 for i=1,1000 do local h=node.heap() print(i,collectgarbage('count'),h,h2-h) h2=h a[i]={} tmr.wdclr() end


Carsten

Re: Out of memory but heap shows about 5kb available

PostPosted: Wed Apr 15, 2015 12:05 am
by pit
I run this again on the 20150406 INTEGER build and it looks much better:
Code: Select all> a={} for i=1,1000 do print(i,collectgarbage('count'),node.heap()) a[i]={} tmr.wdclr() end
1       4       20240
2       4       20128
3       4       20064
...
326     18      344
327     18      296
328     18      248
not enough memory


The 20150406 FLOAT build also shows better results now but out of memory at 2.5kb free heap still seams high.
Code: Select all> a={} for i=1,1000 do print(i,collectgarbage('count'),node.heap()) a[i]={} tmr.wdclr() end
1       5.3486328125    19096
2       5.4267578125    18968
3       5.4580078125    18920
...
256     17.3486328125   2608
257     17.3798828125   2560
258     17.4111328125   2512
not enough memory

Does anyone know why?

Thanks,
pit

Re: Out of memory but heap shows about 5kb available

PostPosted: Wed Feb 24, 2016 12:36 am
by pit
After a long time now i run another test using this build:
Code: Select allNodeMCU custom build by frightanic.com
        branch: master
        commit: c8037568571edb5c568c2f8231e4f8ce0683b883
        SSL: false
        modules: adc,bmp085,dht,enduser_setup,file,gpio,i2c,mqtt,net,node,pwm,rtctime,sntp,spi,tmr,uart,wifi,ws2812
 build  built on: 2016-02-07 06:45
 powered by Lua 5.1.4 on SDK 1.4.0


Much more heap memory is available now that's great, but it still runs out of memory at 8k - why??
... using Casten's line this time:
Code: Select all> a={} h2=0 for i=1,1000 do local h=node.heap() print(i,collectgarbage('count'),h,h2-h) h2=h a[i]={} tmr.wdclr() end
1       4.712890625     41064   -41064
2       4.791015625     40904   160
3       4.822265625     40856   48
...
512     28.712890625    8080    48
513     28.744140625    8032    48
514     28.775390625    7984    48
not enough memory