C++ 我是否在这里泄漏内存(使用GNU GSL插值)?

C++ 我是否在这里泄漏内存(使用GNU GSL插值)?,c++,pointers,gsl,C++,Pointers,Gsl,我正在使用GNU GSL库做一些插值 double Interpolator::calculateInterpolant(const InterpTypes& TYPE) { double interpolant; const int SIZE = predictor_.size(); gsl_interp * interp = allocateInterpolationObject(TYPE, SIZE); gsl_interp_init(interp

我正在使用GNU GSL库做一些插值

double Interpolator::calculateInterpolant(const InterpTypes& TYPE)
{
    double interpolant;
    const int SIZE = predictor_.size();

    gsl_interp * interp = allocateInterpolationObject(TYPE, SIZE);
    gsl_interp_init(interp, &predictor_[0], &response_[0], SIZE);
    gsl_interp_accel * acc = gsl_interp_accel_alloc();
    interpolant = gsl_interp_eval(interp, &predictor_[0], &response_[0],  
        level_, acc);
    gsl_interp_free(interp);
    gsl_interp_accel_free(acc);
    return interpolant;
}
我关心的函数是
allocateInterpolationObject
。以下是该函数的主体:

gsl_interp * allocateInterpolationObject(const InterpTypes& TYPE, 
    const int& SIZE)
{
    gsl_interp * interp;
    switch (TYPE){
        case LINEAR:
            interp = gsl_interp_alloc(gsl_interp_linear, SIZE);
            break;
        case CSPLINE:
            interp = gsl_interp_alloc(gsl_interp_cspline, SIZE);
            break;
        case AKIMA:
            interp = gsl_interp_alloc(gsl_interp_akima, SIZE);
            break;
    }
    return interp;
}
我知道我在程序的某个地方泄漏内存,我怀疑它可能在这里,因为我没有在
allocateInterpolationObject
函数中释放对象
interp
(即使我在
calculateInterpolant
函数中释放它)。但是我怎样才能在归还之前释放一些东西呢?我是一个“指针新手”,我可以在这里使用一些建议或澄清。多谢各位

我知道我在程序中的某个地方泄漏内存,我怀疑

…就停在那里。千万不要在怀疑的情况下做这样的事情。你通常是错的。使用内存调试器确定泄漏的是哪个分配,跟踪分配对象(以及指向它的指针)的传递方式,并在最后一个指针被“删除”时添加空闲对象

内存调试的“转到太”是。使用它

但是我怎样才能在归还之前释放一些东西呢

你没有

alloc/free不是必须在每个函数范围级别上平衡的东西。规则是,所有被分配的东西最终都必须是免费的,但什么时候应该这样做取决于你