Skip to content

Commit 7ccb39e

Browse files
committed
[feature] popSIFT instance counter to free resources
fixes a bug appearing after alicevision/popsift/pull/71
1 parent 352ed54 commit 7ccb39e

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/aliceVision/feature/sift/ImageDescriber_SIFT_popSIFT.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
#include <popsift/sift_octave.h>
1515
#include <popsift/common/device_prop.h>
1616

17+
#include <atomic>
18+
1719
namespace aliceVision {
1820
namespace feature {
1921

2022
std::unique_ptr<PopSift> ImageDescriber_SIFT_popSIFT::_popSift = nullptr;
23+
std::atomic<int> ImageDescriber_SIFT_popSIFT::_instanceCounter{0};
2124

2225
void ImageDescriber_SIFT_popSIFT::setConfigurationPreset(EImageDescriberPreset preset)
2326
{
@@ -95,5 +98,23 @@ void ImageDescriber_SIFT_popSIFT::resetConfiguration()
9598
_popSift.reset(new PopSift(config, popsift::Config::ExtractingMode, PopSift::FloatImages));
9699
}
97100

101+
ImageDescriber_SIFT_popSIFT::ImageDescriber_SIFT_popSIFT(const SiftParams& params, bool isOriented)
102+
: ImageDescriber()
103+
, _params(params)
104+
, _isOriented(isOriented)
105+
{
106+
_instanceCounter++;
107+
}
108+
109+
ImageDescriber_SIFT_popSIFT::~ImageDescriber_SIFT_popSIFT()
110+
{
111+
_instanceCounter--;
112+
113+
if(_instanceCounter.load() == 0)
114+
{
115+
_popSift.reset(nullptr);
116+
}
117+
}
118+
98119
} // namespace feature
99120
} // namespace aliceVision

src/aliceVision/feature/sift/ImageDescriber_SIFT_popSIFT.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ namespace feature {
2626
class ImageDescriber_SIFT_popSIFT : public ImageDescriber
2727
{
2828
public:
29-
ImageDescriber_SIFT_popSIFT(const SiftParams& params = SiftParams(), bool isOriented = true)
30-
: ImageDescriber()
31-
, _params(params)
32-
, _isOriented(isOriented)
33-
{}
29+
explicit ImageDescriber_SIFT_popSIFT(const SiftParams& params = SiftParams(), bool isOriented = true);
3430

3531
/**
3632
* @brief Check if the image describer use CUDA
@@ -109,13 +105,19 @@ class ImageDescriber_SIFT_popSIFT : public ImageDescriber
109105
regions.reset(new SIFT_Regions);
110106
}
111107

108+
/**
109+
* @brief Destructor
110+
*/
111+
~ImageDescriber_SIFT_popSIFT() override;
112+
112113
private:
113114

114115
void resetConfiguration();
115116

116117
SiftParams _params;
117118
bool _isOriented = true;
118119
static std::unique_ptr<PopSift> _popSift;
120+
static std::atomic<int> _instanceCounter;
119121
};
120122

121123
} // namespace feature

0 commit comments

Comments
 (0)