Memory leaks

I have done my homework on this subject. Here is the deal. I run valgrind (a memory checker for my program) and it says that there is no leaks. However after my program runs for about an 1 hour is uses up about 100mb.
I am 99% sure that all malloc'd data is being deleted.
my question is this.
If I have a function that is local that has varables like:
void function()
{
char* a;
int a;
}
This is actually a function that is part of a class, but as far as I know I do not need to delete or free local varables and when I tried I got error's.
I have a lot of funtions using char *prt to find an other prt inside that prt or char *a; char *b; a=b;
Totaly confused. If you can help I would be very happy.
Thank you in advance if possible,
Don
P.s. how do I find a list of new unanwsered posts, so I can help do my part anwsering questions that I do know.
Every Thread with a "New" in a blue box after its title;)...

Where is your code?... (Use code tags [below "Format:"])
Last edited on
One quick note about terminology: 'malloc' and 'free' are the standard 'C' style dynamic memory allocation, whereas 'new' and 'delete' are specific to C++. Assuming you are using C++ and not actually 'malloc' or 'free'ing anything, you should stick to use 'new' and 'delete' in your questions. Unless of course you are actually mixing and matching in your code, which could be the source of your memory leak right there!

Assuming that's not the case, the answer to your question is 'no' - local variables do not need to be deleted by nature of their being local. Every 'new' needs to be matched with a 'delete'. Besides that, you also need to make sure classes you use that are later subclassed have virtual destructors, ensuring their dynamically allocated memory is eventually deleted.

--Rollie

It is the virtual destructor, did not realize that was compulsory.
I will do my homework on that and if I have no question close the forum.
Thank you,
I have been pulling my hair out for over a month about this.
Don
Ok, but one question here: I have my code set up as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|* the url.h file*/
#include "UrlInfo.h"
urlinformation CurrentUrl;
void urlinformation::callparse();
{
    for (int a; a <100000; a ++
 	{
		CurrentHTML.StartParseHtmlCode();
	{
};

#ifndef URLINFO_H_INCLUDED
#define URLINFO_H_INCLUDED
/* the url.cpp file*/
#include parse.h and url.h
class urlinformation
{
    public:
	void callparse();
};
extern urlinformation CurrentUrl;

#endif // URLINFO_H_INCLUDED

/*  this is parse.h file */
#include "MySqlConnection.h"

class ParseHtml
{
    public:
        // Public funtion for starting the HTML parser
        void StartParseHtmlCode();
    private:
        // private storage varablles
        char TempLinkTitle[8000];
        // private functions for breaking down code
        void ClearInfo();
        
};extern ParseHtml CurrentHTML;


#endif // PARSEHTML_H_INCLUDED

/* this is the parse.cpp file */
#include "ParseHtml.h"

ParseHtml CurrentHTML;
void ParseHtml::StartParseHtmlCode()
{
    ClearInfo();
};

void ParseHtml::ClearInfo()
{
    TempLinkTitle[0] = '\0';
};


The question is if I have decalred this classes once I should not have to distructe them.
But confused.
Thanks,
Don
Nothing wrong with the code you posted, but that's to be expected - there isn't any memory management anywhere.
Just remember that each new needs a delete, that each new[] needs a delete[] and that delete/delete[] can be avoided almost completely if you follow RAII and use containers properly.
Found the leak. I wrote two functions that malloc the data only once, but forgot to set the bool that tells me to free it in one. Figured it out by shutting down function at a time, till the leak stopped.
Thanks for all the help.
Topic archived. No new replies allowed.