-->
Page 1 of 1

Heap not released

PostPosted: Sun Jan 31, 2016 11:36 am
by rddezh9
Hi,

I'm trying to read temperature and pressure from BMP180 sensor with my ESP8266. I want to display those numbers on 128x64 screen. BMP180 works perfectly, and I have also managed to write display driver. However, when I put those two pieces together I get "Run out of memory" exception.

According to my research, I should be able to release heap used by BMP180 library with following commands:
Code: Select allbmp180 = nil
package.loaded["bmp180"]=nil


So I tried the following code:
Code: Select allprint("start "..node.heap())
bmp180 = require("bmp180")
bmp180.init(I2C_SDA, I2C_SCL)
bmp180.read(OSS)
t = bmp180.getTemperature()
p = bmp180.getPressure()
print("finished "..node.heap())
bmp180 = nil
package.loaded["bmp180"]=nil
print("unloaded "..node.heap())


But the result is:
Code: Select allstart 26752
finished 20424
unloaded 20376

The collectgarbage() method doesn't help either. So why am I still missing 6000 bytes? Am I doing anything wrong? Is there another way to clear my heap?

Thanks for help

Re: Heap not released

PostPosted: Mon Feb 01, 2016 7:23 pm
by TerryE
A quick look shows that UT and B5 are global. You need to check _G

Re: Heap not released

PostPosted: Tue Feb 02, 2016 5:00 am
by rddezh9
So I tried to add UT and B5 among other local variables, but my heap report is still same:
Code: Select allstart 28864
finished 20720
unloaded 20648


I also tried to add
Code: Select alltable.foreach(_G,print)
to see _G contents, but I dont see anything suspicious in it:
Code: Select allmodule   function: 0x3fff38d0
I2C_SDA   1
pairs   function: 0x3fff31b0
newproxy   function: 0x3fff3270
package   table: 0x3fff33e0
_G   table: 0x3fff22e8
__index   lightfunction: 0x402634b8
ipairs   function: 0x3fff30c0
p   96801.700794684
t   202.49257921691
c   ΕΎ7
OSS   1
require   function: 0x3fff3920
I2C_SCL   2