Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak SunMoonCalc #144

Closed
Leonos opened this issue Oct 31, 2018 · 4 comments
Closed

Memory leak SunMoonCalc #144

Leonos opened this issue Oct 31, 2018 · 4 comments

Comments

@Leonos
Copy link

Leonos commented Oct 31, 2018

Is anyone else getting this?

8<------------------------ BUG REPORT -----------------------------------------

Actual behavior

Every run of
SunMoonCalc smCalc = SunMoonCalc(1541023330, 52.520008, 13.404954);
const SunMoonCalc::Result result = smCalc.calculateSunAndMoonData();

takes around 2500 bytes from memory and soon nothing is left. See Serial output.

1541052141
32592
Sun
1541052141
30080
Sun
1541052141
27568
Sun
1541052141
25056
Sun
1541052141
22544
Sun
1541052141
20032
Sun
1541052141
17520
Sun
1541052141
15008
Sun
1541052141
12496
Sun
1541052141
9984
Sun
1541052141
7472
Sun
1541052141
4960
Sun
1541052141
2448

Exception (29):
epc1=0x4020576f epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000


Test code

https://github.com/ThingPulse/esp8266-weather-station/tree/master/examples/SunMoonCalcDemo
The example (SunMoonCalcDemo.ino) brought back to absolute minimum, moving the calculation from setup() to loop(), demonstrates this behavior:

#include "SunMoonCalc.h"

void printResult(SunMoonCalc::Result result) {
  Serial.println("Sun");
  Serial.println(result.sun.rise);
}

void setup() {
  Serial.begin(115200);
  delay(500);
  Serial.println();
}

void loop() {
  if (millis() % 5000 == 0) {
    SunMoonCalc smCalc = SunMoonCalc(1541023330, 52.520008, 13.404954);
    const SunMoonCalc::Result result = smCalc.calculateSunAndMoonData();
    printResult(result);
    Serial.println(ESP.getFreeHeap());
  }
}

Hardware

Adafruit's ESP8266 Feather Huzzah; Arduino core 2.4.2, Arduino IDE 1.8.5
8<------------------------ END BUG REPORT -------------------------------------

@marcelstoer marcelstoer added the bug label Nov 1, 2018
@marcelstoer
Copy link
Member

We haven't verified ourselves yet but that's a pretty convincing bug report, thanks.

@Leonos
Copy link
Author

Leonos commented Nov 1, 2018

Thanks, Marcel.
It also happens on an ESP32 (obviously).

EDIT: what I previously wrote here about ESP32 being able to recover from this is unfortunately not true. It does restart while an ESP8266 crashes without being able to restart. At least for the ones that I tested.

@ThingPulse ThingPulse deleted a comment from OrakelKSL Nov 4, 2018
@OrakelKSL
Copy link

OrakelKSL commented Nov 4, 2018 via email

@marcelstoer
Copy link
Member

marcelstoer commented Feb 24, 2019

@Leonos that's a weird one, indeed.

  • Setting the SunMoonCalc object back to void (as below) makes no difference.
  • Not calling calculateSunAndMoonData() does make a difference - no leak.
SunMoonCalc *smCalc = new SunMoonCalc(now - dstOffset, currentWeather.lat, currentWeather.lon);
moonData = smCalc->calculateSunAndMoonData().moon;
delete smCalc;
smCalc = nullptr;

It must have something to do with the way those functions return their results as structs.

@jgromes jgromes mentioned this issue Mar 21, 2019
3 tasks
marcelstoer pushed a commit that referenced this issue Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants