I am using VLD to detect any memory leaks. The following code is reporting a memory leak.
Display All
My question is once sample is added to samples, is the local pointer to sample still needed? If I delete sample, will this cause the samples vector to have an invalid pointer?
The definition of samples is as below:
typedef std::vector<Sample*> Samples;
typedef std::vector<Sample*>::iterator Iterator;
Samples samples;
Source Code
- bool Audio::Load(std::string filename, std::string name)
- {
- if (filename.length() == 0 || name.length() == 0) return false;
- Sample *sample = new Sample();
- sample->setName(name);
- try { FMOD_RESULT res;
- res = FMOD_System_CreateSound( system, //FMOD system filename.c_str(), //filename
- FMOD_DEFAULT, //default audio
- NULL, //n/a
- &sample->sample);
- //pointer to sample if (res != FMOD_OK)
- { return false; } } catch (...) { return false; }
- samples.push_back(sample);
- return true;
- }
My question is once sample is added to samples, is the local pointer to sample still needed? If I delete sample, will this cause the samples vector to have an invalid pointer?
The definition of samples is as below:
typedef std::vector<Sample*> Samples;
typedef std::vector<Sample*>::iterator Iterator;
Samples samples;