guineawheek / endercv

Yo! This project has run it's course. Try [this](https://github.com/OpenFTC/EasyOpenCV) instead!
Other
0 stars 0 forks source link

Memory Leak on Galaxy S5s #8

Closed DreekFire closed 5 years ago

DreekFire commented 5 years ago

I tried running my own vision code on our new Galaxy S5 phones but it was crashing after about 25 seconds, so I opened up the memory profiler and saw that the memory usage was rapidly climbing to 1GB, at which point the phones crashed.

I tried running both the example code and a blank OpenCVPipeline (processFrame() was just "return rgba;") and still ran into the issue.

In order to resolve this I made the following edits to OpenCVPipeline.java:

  1. I turned rgba and gray in onCameraFrame() in OpenCVPipeline into member variables and added another member variable called res which is a Mat
  2. Initialized all three to new Mat() at the beginning of the class
  3. then in onCameraFrame() I do rgba.release(); gray.release(); res.release();
  4. I reinitialize rgba and gray to new Mat()
  5. Set res = processFrame(rgba, gray) in onCameraFrame() just above the return statement in order to maintain a reference to that Mat
  6. Returned res

Based on a discussion with several other programmers on Discord, we believe this may be because the Java Garbage Collector collects the Java references to the Mats but does not trigger deletion of the Mats themselves in the native code.

Thanks, Derek Guo FTC Team 8375 Programmer

guineawheek commented 5 years ago

fixed with #9