#Memory leaks aparently😔

88 messages · Page 1 of 1 (latest)

shrewd perch
#

Valgrind keeps telling me im mismanaging memory somewhere but cant find any. Have tried myself, and with the use of ChatGpt.

Please help me find the issue.

Can add more code/info if needed.

blissful idolBOT
sick mesa
#

Try runnig with address sanitizer

#

!asan

#

Huh..., why is the bot not working

shrewd perch
sick mesa
#

How are you compiling your code?

shrewd perch
#

Well personally, with visual studio. But i hand it in Via codeGrader, and im not sure how they do it...

sick mesa
shrewd perch
#

thankss

#

IM getting the error "LINK : fatal error LNK1561: entry point must be defined"

sick mesa
#

Does jumper have a main function?

#

Sorry I don't develop on windows so my experience is limited

shrewd perch
#

yeah, i think i fixed it

shrewd perch
#

so what do i do now that the sanitization is done?

sick mesa
#

Run it, and if a memory problem arises it will scream at you with great detail

shrewd perch
#

haha ok

#

i think its telling me its the constructor... but i really dont se whats wrong with it

deep bay
#

The constructor doesn't have a definition anywhere

#

Only a declaration

#

According to the message

shrewd perch
#

based on the code i put in, is that true?

cedar wind
#

thats weird then

#

the file u posted does have Jumper::Jumper(std::string name, int startNr, int totalNrOfJumps)

deep bay
#

Where do you have your main? It seems like it didn't compile the file with definitions

shrewd perch
#

in the same folder as jumper

idle nova
#

whats the output of valgrind?

shrewd perch
idle nova
#

jumper.cpp line 12

shrewd perch
#

yeah... i still dont get it

#

my line 12 is just defining the array

sick mesa
#

Do you delete the array in the destructor?

shrewd perch
shrewd perch
sick mesa
#

What if you assign a jumper to itself?

#

Also I assume of you have a copy constructor as well?

shrewd perch
shrewd perch
#

this one?

idle nova
#

so that valgrind error btw tells you that that memory is still not freed somewhere, it should also report this at the bottom

shrewd perch
sick mesa
shrewd perch
shrewd perch
idle nova
#

Well that’s not a copy constructor

median garden
#

you have done many edits and we can't track what you did

shrewd perch
tall kiteBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

tall kiteBOT
#

This question thread is being automatically marked as stale.

median garden
shrewd perch
median garden
# shrewd perch

you have a missing virtual destructor in the base class Competitor

#

this is exactly why you get leaks

#

once implemented, all derived classes will also have an implicit virtual destructor

shrewd perch
#

there is a destructor, however iv left it empty

#

do i need to put some code in it?

median garden
#

this is correct

#

show me your main.cpp where you use these classes

#

how do you create them and how do you destroy them

median garden
#

they are leaking the memory

#

the author of these tests is a fool

shrewd perch
#

haha

median garden
shrewd perch
#

yea, ig ill mail them

#

thanks for your help

#

i was unsure wether it was my code or not so helps alot

median garden
#
TEST_CASE("test of toString() for Jumper using base class pointers")
{
    Competitor* compTwo = new Jumper("Ken", 200, 3);

    compTwo->addResult(4.56);
    compTwo->addResult(7.12);
    compTwo->addResult(6.54);

    REQUIRE(compTwo->toString().find("Ken") != std::string::npos);
    REQUIRE(compTwo->toString().find("200") != std::string::npos);
    REQUIRE(compTwo->toString().find("4.") != std::string::npos);
    REQUIRE(compTwo->toString().find("7.") != std::string::npos);
    REQUIRE(compTwo->toString().find("6.") != std::string::npos);
}

10/10, will test for leaks again

#

who calls delete on compTwo?

#

NO ONE!

shrewd perch
#

hahahaha

median garden
# shrewd perch hahahaha

Let me guess - the teacher is using Java mainly, but he had to learn and teach C++ because there's a shortage of staff?

#

in some places there is delete for cleanup, in others there isn't

shrewd perch
#

that might be it, honestly i have no idea

tall kiteBOT
#

@shrewd perch Has your question been resolved? If so, run !solved :)

shrewd perch
#

!solved