ARM SDK memory leak?

cpp

#1

Hi,

I need this urgently, because my project is almost at its deadline…

I create a snippet code to show the problem. I am executing this on Raspbian Stretch on Raspberry Pi 3, and it looks like there is some kind of memory leak, because this simple program eats memory really fast, like 50MB/s.

Am I doing something wrong?

g++ main.cpp -o main -std=c++11 -I/usr/local/share/affdex-sdk/include -L/usr/local/share/affdex-sdk/lib -laffdex-native

#include <chrono>
#include <iostream>
#include <thread>
#include “Frame.h”
#include “FrameDetector.h”

#define WIDTH 640
#define HEIGHT 480
#define ITERATIONS 1000

using namespace std;

int main(int argc, char** argsv) {
affdex::FrameDetector detector(30);
affdex::path DATA_FOLDER("/usr/local/share/affdex-sdk/data");
detector.setClassifierPath(DATA_FOLDER);
detector.setDetectAllEmotions(true);
detector.start();
unsigned char *b = new unsigned char[WIDTH * HEIGHT * 3];
for (int s = 1; s < ITERATIONS; s++) {
affdex::Frame frame(WIDTH, HEIGHT, b, affdex::Frame::COLOR_FORMAT::RGB, s);
detector.process(frame);
cout << "Processed frame: " << s << endl;
this_thread::sleep_for(chrono::milliseconds(33));
}
detector.stop();
delete b;
return 0;
}


#2

I have just checked Ubuntu 16.04 x86 and there everything is fine with memory, this program runs without any problems.


ARM SDK Frame Memory Overflow
#3

Hi, Przemek.
Since b is a pointer to an array of characters, you should be able to fix the memory leak by using “delete [ ] b” instead of just “delete b”.

For further reference, here’s a good thread about finding memory leaks in C++ code.

Thanks,
Steve


#4

Thank you Steve. This is indeed a bug in the code. But it doesn’t change anything, because this bug will not cause the program to eat memory up. Also memory is eaten inside the loop, what you can clearly see when running the code and observing taken memory by it.

I will try a different OS and see whether this is reproducible.


#5

OK, looks like the problem doesn’t reproduce on Ubuntu 16.04.
This is weird, as I always thought that Ubuntu is based on Debian (Raspbian).

Ubuntu:
Linux pi-desktop 4.9.37-v7+ #1017 SMP Thu Jul 13 11:26:04 BST 2017 armv7l armv7l armv7l GNU/Linux
Raspbian:
Linux raspberrypi 4.9.41-v7+ #1023 SMP Tue Aug 8 16:00:15 BST 2017 armv7l GNU/Linux


#6