From c84421a2ada0880cad7bf661dddc66e32cee735c Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Tue, 15 Mar 2022 23:04:21 +0100 Subject: [PATCH] fix memory leak --- ESP32/main.ino | 15 ++++++++++++--- bus.cpp | 4 +++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ESP32/main.ino b/ESP32/main.ino index 40d011d..de7cbbe 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -9,8 +9,8 @@ #include "utils.h" #include "error.h" -bus *b = new bus(); -cpu *c = new cpu(b); +bus *b = nullptr; +cpu *c = nullptr; tty *tty_ = nullptr; uint16_t loadbin(bus *const b) @@ -222,6 +222,12 @@ void setup() { Serial.print(F("Size of int: ")); Serial.println(sizeof(int)); + Serial.print(F("CPU clock frequency: ")); + Serial.println(getCpuFrequencyMhz()); + + Serial.print(F("Free RAM before init: ")); + Serial.println(ESP.getFreeHeap()); + Serial.println(F("Init bus")); b = new bus(); @@ -242,6 +248,9 @@ void setup() { exec_addr = loadbin(b); c->setRegister(7, exec_addr); + Serial.print(F("Free RAM after init: ")); + Serial.println(ESP.getFreeHeap()); + pinMode(LED_BUILTIN, OUTPUT); Serial.println(F("Press to start")); @@ -280,7 +289,7 @@ void loop() { Serial.println(F(" *** EMULATION STOPPED *** ")); Serial.print(F("Instructions per second: ")); Serial.println(icount * 1000.0 / (millis() - start_ts)); - delay(1000); + delay(3000); Serial.println(F(" *** EMULATION RESTARTING *** ")); c->setRegister(7, exec_addr); diff --git a/bus.cpp b/bus.cpp index 42c5d1c..746ce95 100644 --- a/bus.cpp +++ b/bus.cpp @@ -16,7 +16,9 @@ bus::bus() : c(nullptr), tm11(nullptr), rk05_(nullptr), rx02_(nullptr), tty_(nullptr) { #if defined(ESP32) - int n = 8; + // ESP32 goes in a crash-loop when allocating 128kB + // see also https://github.com/espressif/esp-idf/issues/1934 + int n = 14; #else int n = 16; #endif