このコードが原因でメモリ リークが発生していますが、その理由はわかりません。
[編集] hereからのコードを問題に含めました:
#include "src/base.cpp"
typedef std::map<std::string, AlObj*, std::less<std::string>,
gc_allocator<std::pair<const std::string, AlObj*> > > KWARG_TYPE;
AlInt::AlInt(int val) {
this->value = val;
this->setup();
}
// attrs is of type KWARG_TYPE
void AlInt::setup() {
this->attrs["__add__"] = new AddInts();
this->attrs["__sub__"] = new SubtractInts();
this->attrs["__mul__"] = new MultiplyInts();
this->attrs["__div__"] = new DivideInts();
this->attrs["__pow__"] = new PowerInts();
this->attrs["__str__"] = new PrintInt();
}
int main() {
while (true) {
AlObj* a = new AlInt(3);
}
}
AlInt は AlObj を継承し、AlObj は gc を継承します。setup() の内容をコメントアウトすると、メモリリークは発生しません。これにより、問題はマップがクリーンアップされていないことにあると思われますが、gc アロケーターを使用しているため、よくわかりません次にどこを見るか。考え?