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 in ConnectedComponents / Labeling class. #63

Closed
benersuay opened this issue Sep 10, 2015 · 0 comments
Closed

Memory Leak in ConnectedComponents / Labeling class. #63

benersuay opened this issue Sep 10, 2015 · 0 comments

Comments

@benersuay
Copy link
Contributor

Symptom:

if a code instantiates several instances of MarkerDetector objects, the following exception occurs:

OpenCV Error: Insufficient memory (Failed to allocate 65408 bytes) in OutOfMemoryError

A quick gdb backtrace shows:
#0 0xb7fdd424 in __kernel_vsyscall ()
#1 0xadb56e0f in __GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#2 0xadb5a455 in __GI_abort () at abort.c:91
#3 0xadda013d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#4 0xadd9ded3 in ?? () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#5 0xadd9df0f in std::terminate() () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#6 0xadd9e0b4 in __cxa_rethrow () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#7 0xae1520a8 in cvFindContours () from/my/directory/lib/libopencv_imgproc.so.2.4
#8 0x08307649 in alvar::LabelingCvSeq::LabelSquares at /my/code/directory/src/ConnectedComponents.cpp
#9 0x082ff1e1 in alvar::MarkerDetectorImpl::Detect at /my/code/directory/MarkerDetector.cpp

Cause:

LabelingCvSeq is derived from Labeling base class. Each new instance of MarkerDetector class gets a pointer to the base (Labeling) class (line 65 of MarkerDetector.h). This pointer is then assigned to a new pointer of the derived class In MarkerDetector.cpp (see line 99 in MarkerDetector.cpp). Derived class allocates memory in its constructor (line 64 in ConnectedComponents.cpp). However when the marker detector object goes out of scope, deleting the pointer to the derived class (line 40 in MarkerDetector.cpp) calls only the base class destructor, and does not call the destructor of the derived class. Since the destructor of the derived class is never being called, allocated memory by opencv is never being released. Thus, multiple instances of MarkerDetector class causes the opencv exception reported above.

benersuay added a commit to benersuay/ar_track_alvar that referenced this issue Sep 10, 2015
sniekum added a commit that referenced this issue Sep 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant