cant clean up memory? Programming Software Development by monkey_king … works as is!, but I can't nail down a memoryleak that shows up when using valgrind. A sample file: small… Re: some interview questions Programming Software Development by sergent …) { clock_t goal; goal = wait + clock(); while(goal > clock()) ; } void memoryleak() { sleep(2000); long long int i = 0; while(i <…;\n\n And now random memory leak!!!!"; sleep(2000); memoryleak(); return 0; }[/CODE] I know, I am evil :p Re: some interview questions Programming Software Development by Tellalca …) { clock_t goal; goal = wait + clock(); while(goal > clock()) ; } void memoryleak() { sleep(2000); long long int i = 0; while(i <…;\n\n And now random memory leak!!!!"; sleep(2000); memoryleak(); return 0; }[/CODE] I know, I am evil :p[/QUOTE… Re: Segmentation error Programming Software Development by Nick Evan …] You never [icode]delete[/icode] the memory you allocated => Memoryleak 2. [icode]float compv( int k, int l, float *P… Re: conversion from char[] Programming Software Development by Nick Evan What Ancient Dragon said ^^, But don't forget do [icode]delete ptr[];[/icode] once you're done with it. Or else you'll get a memoryleak. Re: how to generate random matrix in c Programming Software Development by Nick Evan The whole code looks a bit shaky to be honest... If you're going to use rand() you need to seed the random generator first with srand(). Here's [URL="http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx"]how to do it[/URL]. Also: If you use malloc to allocate memory, be sure to free() it before your program exits. If not: memoryleak :( Re: C++ Deep Copy Linked List Programming Software Development by nayefc So the following shouldn't segfault/memoryleak? [CODE] OrderedSListT(const OrderedSListT<T>& Source) { if (… Re: cant clean up memory? Programming Software Development by Salem > valgrind complains at line 151 the strdup. But I don't know where I should deallocate. In whoever calls get_lex(), just after they've finished with the tokens would be good. Re: cant clean up memory? Programming Software Development by monkey_king Hi thanks for your reply, but I don't know the syntax for clearing something that has been allocted like [CODE=c++] char ***tokens; (*tokens) = new char*[len]; for(int i=0 ; i<len ; i++) (*tokens)[i] =strdup("cstring"); [/CODE] Re: cant clean up memory? Programming Software Development by monkey_king I solved it, strdup uses malloc, so whenever you use a these cstring functions, you should use free and not delete. Re: cant clean up memory? Programming Software Development by Salem Well, your program is a chaotic mix of C and C++. You might want to work on that for a while, before you get too comfortable with the lazy "it works today" approach. Start by replacing all printf() with std::cout and all char arrays (and char pointers) with std::string. Re: cant clean up memory? Programming Software Development by monkey_king [QUOTE=Salem;867700]Well, your program is a chaotic mix of C and C++. You might want to work on that for a while, before you get too comfortable with the lazy "it works today" approach. Start by replacing all printf() with std::cout and all char arrays (and char pointers) with std::string.[/QUOTE] Hi, Thanks for you reply, …