为了解决这一问题, 破碎记忆管理? 班级成员(英国)在“再造”职能中的价值大于1,在“Valgrind”下,我执行整个方案,发现在步骤之前出现一些记忆泄露问题。 在CMFLoader的职能中,有2个明显丧失的问题。
(MyDataset是分子物体的病媒,每个分子物体含有元素)
在CMFLoader:loadFile (vector& MyDataset)中,我最初是
MyDataset.push_back( readMolecule( in_file, word );
where CMFLoader::readMolecule returns a Molecule object. Within the readMolecule function, a new Molecule object is created (but not deleted until the very end of main, more on that later)
Molecule* CMFLoader::readMolecule( ifstream& in_file, string id)
{
Molecule* my_mol = new Molecule( id );
// statements, somewhere along the readFormula function is called
my_mol->setFormula( readFormula( ss ) );
return my_mol;
}
where CMFLoader::readFormula returns an Element object and there is a Molecule::setFormula function to save it to the Molecule object. In readFormula
Elements* CMFLoader::readFormula( stringstream& ss )
{
Elements* my_formula = new Elements();
...
return my_formula;
}
我陷入问题:here,后在主要方案中。 具体问题发生在HammettCheck:check Hammett步骤。 然后,我将上述CMFLoader职能改为类似职能。 我早些时候遇到的问题似乎已经消失(但后来在方案内有一些与记忆泄漏毫不相关的其他问题):
载荷: 文件
Molecule* new_mol = new Molecule(word);
MyDataset.push_back( readMolecule( in_file, word ,new_mol) );
页: 1 分子现在以新的论点Lecule* 行事,新运营商在职能范围内被拆除。 同样,在“Formula”一词中,我现在已经说过。
Elements* new_formula = new Elements();
my_mol->setFormula( readFormula( ss, new_formula ) );
等等。
当然,现在记忆泄漏问题并没有消除! 但是,I 在CMFLoader的任何功能中都不会放到删除的操作员,因为物体后来在主要节目中使用。 具体来说,内容* 用于《陪审团:陪审团判决步骤》,而分子* 用于方案目的。
主要方案就是这样。
int main(int argc, char* argv[]){
//initialising an empty array to store our molecules.
vector<Molecule*> MyDataset;
//Read command line inputs.
InputReader* MyInputs = new InputReader();
if( !MyInputs->readInputs(argc, argv) ) {delete MyInputs;return -1;}
//Load CMF file.
CMFLoader* MyLoader = new CMFLoader( MyInputs );
unsigned int min_same_grp = MyLoader->getmin(); //define minimum no of same hammett groups for structure
if( !MyLoader->loadFile( MyDataset ) ) {delete MyLoader;delete MyInputs;return -1;}
delete MyLoader;
cout << MyDataset.size() << " molecules loaded" << endl;
//Remove molecules which are too large.
BigFilter* MyBigFilter = new BigFilter( MyInputs );
if( !MyBigFilter->filterBigLigands( MyDataset ) ) {delete MyBigFilter;delete MyInputs;return -1;}
delete MyBigFilter;
cout << "Molecules left after big ligand filter: " << MyDataset.size() << endl;
//Mark any Hammetts groups found in molecules.
HammettCheck* MyHammettCheck = new HammettCheck(min_same_grp);
if( !MyHammettCheck->loadHammetts() ) {delete MyHammettCheck;delete MyInputs;return -1;}
if( !MyHammettCheck->checkHammett( MyDataset ) ) {delete MyHammettCheck;delete MyInputs;return -1;}
delete MyHammettCheck;
cout << "Molecules containing Hammett Groups: " << MyDataset.size() << endl;
ConjugationCheck* MyConjugationCheck = new ConjugationCheck(min_same_grp);
if( !MyConjugationCheck->checkConjugation( MyDataset ) ) {delete MyConjugationCheck;delete MyInputs;return -1;}
delete MyConjugationCheck;
cout << "Molecules containing conjugated Hammett Groups: " << MyDataset.size() << endl;
DataAdder* MyDataAdder = new DataAdder( MyInputs );
if( !MyDataAdder->addData( MyDataset ) ) {delete MyDataAdder; delete MyInputs;return -1;}
delete MyDataAdder;
//Sorts molecules based on their NLO rating given by NLOCompare.
if (min_same_grp ==1) {sort(MyDataset.begin(), MyDataset.end(), NLOCompare);}
else {sort(MyDataset.begin(), MyDataset.end(), OctuNLOCompare);}
//Saves a new CIF file containing just the predicted NLO molecules.
FileSaver* MyFileSaver = new FileSaver( MyInputs );
if( !MyFileSaver->saveFile( MyDataset ) ) {delete MyFileSaver;delete MyInputs;return -1;}
delete MyFileSaver;
/*
Saves a txt file which can be imported into Excel, showing the
paths to each of the selected Hammett groups in a molecule.
*/
ExcelSaver* MyExcelSaver = new ExcelSaver( MyInputs );
if( !MyExcelSaver->saveFile( MyDataset ) ) {delete MyExcelSaver;delete MyInputs;return -1;}
delete MyExcelSaver;
//Cleans the memory before exiting the program.
for(unsigned int i=0; i < MyDataset.size(); i++){
delete MyDataset[i];
}
delete MyInputs;
return 0;
}
在方案的各个要点,如果摩鹿农酋长院的MyDataset[i]不符合某些条件,则使用该办法予以拆除。
MyDataset.pop_back();
因此,这将叫作摩洛丽斯·德斯鲁克。
Molecule::~Molecule(void)
{
//Deletes all atoms in molecule.
for(unsigned int i=0; i < mol_atoms.size(); i++){
delete mol_atoms[i];
}
//Deletes all bonds in molecule.
for(unsigned int i=0; i < mol_bonds.size(); i++){
delete mol_bonds[i];
}
//Deletes the class of elements contained.
delete mol_formula;
}
www.un.org/spanish/ecosoc 我不相信这里有什么错误。 如何解决记忆泄漏问题?
我的Valgrind Memcheck Leak 摘要中的“无限期损失”问题
==34809== 400 (96 direct, 304 indirect) bytes in 2 blocks are definitely lost in loss record 24 of 33
==34809== at 0x1000A0679: malloc (vg_replace_malloc.c:266)
==34809== by 0x1000F7F04: operator new(unsigned long) (in /usr/lib/libstdc++.6.0.9.dylib)
==34809== by 0x10000A3B4: CMFLoader::readMolecule(std::basic_ifstream<char, std::char_traits<char> >&, std::string, Molecule*) (in ./OctuDiscovery)
==34809== by 0x10000B9EE: CMFLoader::loadFile(std::vector<Molecule*, std::allocator<Molecule*> >&) (in ./OctuDiscovery)
==34809== by 0x10000282E: main (in ./OctuDiscovery)
==34809== 12,833 (152 direct, 12,681 indirect) bytes in 1 blocks are definitely lost in loss record 33 of 33
==34809== at 0x1000A0679: malloc (vg_replace_malloc.c:266)
==34809== by 0x1000F7F04: operator new(unsigned long) (in /usr/lib/libstdc++.6.0.9.dylib)
==34809== by 0x10000B93B: CMFLoader::loadFile(std::vector<Molecule*, std::allocator<Molecule*> >&) (in ./OctuDiscovery)
==34809== by 0x10000282E: main (in ./OctuDiscovery)