Flann Index release memory unexpectedly. (Bug #2536)
Description
class AClass {
public:
AClass(){
}
private:
Index ind;
}
AClass::AClass(){
code to load feavec from text files....
ind = Index(feavec, parms);
}
ind cannot be used any more, since after the assignment, the local copy's ~Index will be called, and member index won't be retained. As a result, the member var ind will have an invalid pointer void index.
Associated revisions
Merge pull request #2536 from ilya-lavrenov:tapi_resize_linear
History
Updated by Stefan R over 12 years ago
Disclaimer: I have not used that FLANN part of OpenCV but the separate library.
This is most likely not a bug. You must hold the vectors that are being indexed by FLANN in memory.
As long as `ind` is valid, `feavec` must contain the vectors and must not be released.
Updated by Lichao Chen over 12 years ago
Yes, you are right, and I did keep feavec unreleased, the problem is that, besides the data vector(which is feavec here), the flann also generates some index info, which is stored in void* index, and it will be released once the local copy is not accessible. I resolved this problem by using
+ Index *ind;
- Index *ind;
+ ind = new Index(feavec, parms);
- ind = Index(feavec, parms);
So instead of doing a Index object copy, I just assign the pointer here, and it works now.
Stefan R wrote:
Disclaimer: I have not used that FLANN part of OpenCV but the separate library.
This is most likely not a bug. You must hold the vectors that are being indexed by FLANN in memory.
As long as `ind` is valid, `feavec` must contain the vectors and must not be released.
Updated by Andrey Kamaev over 12 years ago
Close as not a bug.
- Target version set to 2.4.4
- Status changed from Open to Cancelled
Updated by Lichao Chen over 12 years ago
http://code.opencv.org/issues/2050
Then you should also close this one. they are identical
Andrey Kamaev wrote:
Close as not a bug.
Updated by Andrey Kamaev over 12 years ago
That issue has a good point about documentation update. So lets keep it open.
I've marked this as a duplicate of #2050