当我以固定利率债券提取和迭代现金流时,Valgrind报告内存泄漏。我使用以下代码:
FixedRateBond fixedRateBond(
settlementDays,
faceAmount,
fixedBondSchedule,
std::vector<Rate>(1, couponRate),
ActualActual(ActualActual::Bond),
BusinessDayConvention ::Unadjusted,
redemption,
issueDate
);
vector<boost::shared_ptr<CashFlow>> cashFlows = fixedRateBond.cashflows();
for (size_t i=0; i != cashFlows.size(); ++i) {
cout << "Date: " << cashFlows[i]->date() << " Amount: " << cashFlows[i]->amount() <<endl;
}
编辑:看起来这是一个OSX问题,因为相同的代码在Linux中运行时不会引起任何问题。对于后代,这是我在OSX上得到的报告:
==62096== 148 (80 direct, 68 indirect) bytes in 1 blocks are definitely lost in loss record 170 of 208
==62096== at 0x1001F8EA1: malloc (vg_replace_malloc.c:303)
==62096== by 0x102D3D4A2: __Balloc_D2A (in /usr/lib/system/libsystem_c.dylib)
==62096== by 0x102D3DDEB: __d2b_D2A (in /usr/lib/system/libsystem_c.dylib)
==62096== by 0x102D3A443: __dtoa (in /usr/lib/system/libsystem_c.dylib)
==62096== by 0x102D6307A: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==62096== by 0x102D8C35C: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==62096== by 0x102D705A8: _vsnprintf (in /usr/lib/system/libsystem_c.dylib)
==62096== by 0x102D70607: vsnprintf_l (in /usr/lib/system/libsystem_c.dylib)
==62096== by 0x102D60AB1: snprintf_l (in /usr/lib/system/libsystem_c.dylib)
==62096== by 0x102ACD752: std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >::do_put(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, std::__1::ios_base&, char, double) const (in /usr/lib/libc++.1.dylib)
==62096== by 0x102AB3B33: std::__1::basic_ostream<char, std::__1::char_traits<char> >::operator<<(double) (in /usr/lib/libc++.1.dylib)
==62096== by 0x10000A2D1: main (main.cpp:31)
答案 0 :(得分:0)
这似乎与OS X有关,因为问题不会发生在Linux上,并且(总是有用的)Luigi状态不在QuantLib代码本身。