valgrind 3.5.0을 실행하여 프로그램에서 메모리 누출을 시도합니다. 그래서로 호출 :혼란스러운 Valgrind 출력 : 간접적으로 블록이 손실되었지만 오류가 없습니까?
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes
을 내 프로그램은 내가 할당과 해방의 수가 일치하지 않는 것을 걱정 0 오류가 있음을 Valgrind의이
==22926==
==22926== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from 1)
==22926== malloc/free: in use at exit: 20,862 bytes in 425 blocks.
==22926== malloc/free: 25,361 allocs, 24,936 frees, 772,998 bytes allocated.
==22926== For counts of detected errors, rerun with: -v
==22926== searching for pointers to 425 not-freed blocks.
==22926== checked 91,884 bytes.
것을 말해에도 불구하고보고 완료되면 . 더 걱정 여전히 다음
==22926== LEAK SUMMARY:
==22926== definitely lost: 68 bytes in 1 blocks.
==22926== indirectly lost: 20,794 bytes in 424 blocks.
==22926== possibly lost: 0 bytes in 0 blocks.
==22926== still reachable: 0 bytes in 0 blocks.
==22926== suppressed: 0 bytes in 0 blocks.
누출로 보이는 관련된 추가 출력 있습니다 : OneTwoThree의 생성자에서 해당 라인에서
==22926== 20,862 (68 direct, 20,794 indirect) bytes in 1 blocks are definitely lost in loss record 9 of 17
==22926== at 0x40269EE: operator new(unsigned int) (vg_replace_malloc.c:224)
==22926== by 0x807960B: OneTwoThree::OneTwoThree(Scenario const*) (onetwothree.cc:22)
==22926== by 0x804DD69: main (scsolver.cpp:654)
나는 다음과 같은 한이 :
OneTwoThree::OneTwoThree (const Scenario* scenario) :
Choice("123", scenario, new Solution (scenario->name(), scenario)),
seen_(new bool [sol_->numVisits()])
{
}
후, 소멸자, seen_ 그래서 같이 삭제 :
,OneTwoThree::~OneTwoThree()
{
delete [] seen_;
}
seen_와 연관된 메모리의 재 할당이 없습니다. 내 프로그램을 실행하는 동안 부울을 true/false로 바꿉니다.
여기에 누출이 보이지 않으며 valgrind가 말해 주려하는 것을 이해하지 못합니다. 나는 valgrind 설명서 (특히 this)를 통해 읽고 있었지만 나는 많이 계몽 적이 지 않습니다.
누구나 저 출력을 도와 줄 수 있습니까?
'Solution' 객체 * 자체는 결코 파괴되지 않을 수 있습니까? – Artelius
Choice 클래스는 생성자에서 가져 오는 포인터의 할당을 해제합니까? OneTwoThree가 메모리를 할당하면 동일한 인스턴스가 메모리를 할당 해제해야하는 것처럼 더 나은 디자인이 같은 클래스의 포인터 소유권을 갖는 것 같습니다. –
Choice 생성자와 그 친척은 모든 것을 완전히 해제합니까? –