Memory Issue when freeing std::vector< MultiScalarField2D<T>* >

Hello everyone,

I need to create a vector of MultiScalarFields where I do not know the number of fields or their size at compile time. The code I wanted to use was

#include “palabos2D.h”
#include “palabos2D.hh”


using namespace plb ;
using namespace std ;

typedef double T ;

int main(int argc, char* argv[]) {
plbInit(&argc, &argv);

// Field size
const plint n = 5 ;

// Number of fields
const plint num = (plint) 3 ;

std::vector<MultiScalarField2D<T>* > fields ;

// Allocate memory
for(plint i=0; i<num; ++i) {
	fields.push_back(new MultiScalarField2D<T> (n,n) ) ;

// Modifiy random entry
setToConstant(*fields[0],Box2D(n/2,n/2,n/2,n/2),(T)19) ;
pcout << fields[0]->get(n/2,n/2) << endl ;

// Free memory
for(plint i=0; i<num; ++i) {
	delete(fields[i]) ;
fields.clear() ;


However, when I run Valgrind on this problem, it detects memory leakages. But I cannot find out what I am doing wrong and the way I am freeing up space was suggested in some other forum threads, e.g.

Any help is appreciated