memory leakage

M

madhawi

i want to know that on what situation memory leakage happan and what
is the solution to solve the problem of memory leakage.
 
M

madhawi

i m working on a large project. and i used free() for memory. but
still i get problem. when i removed the line from where i m getting
memory leakage, then i get another problem, loss of information.
 
R

raxitsheth2000

i want to know that on what situation memory leakage happan and what

<forwarded to comp.programming>

you allocate some memory,
you use those memory,
now you dont want the memory --you have done(and you should free the
memory)

you forgot to free the memory and go ahead, and now you cant come back
to free the memory.

i think this is called leak (I may need to more correct but this is
what basics come to my mind,)

http://en.wikipedia.org/wiki/Memory_leak
http://www.valgrind.org/docs/manual/quick-start.html#quick-start.prepare

is the solution to solve the problem of memory leakage.

yes, it is solvable,
1. Good Programming habits,
2. Good Toolset (for linux valgrind/memprof is reasonably good,)

--Raxit
 
M

madhawi

i am using c++. i used delete and destructor to free the memory. can u
help me this in c++, please.
 
I

Ian Collins

madhawi wrote:

Please don't top-post.
i m working on a large project. and i used free() for memory. but
still i get problem. when i removed the line from where i m getting
memory leakage, then i get another problem, loss of information.

Please capitalise your sentences and 'I'.

Assuming your debugger supports is it, run the program with leak
checking enabled. If it doesn't, ask on a platform specific group about
tools to do this for you.

If you build your application in small, tested, steps checking for leaks
as you go, you stand a better chance of avoiding these problems.
 
I

Ian Collins

madhawi said:
i am using c++. i used delete and destructor to free the memory. can u
help me this in c++, please.

u doesn't post here any more.

Sounds like you should either be asking on a C++ or Linux programming group.
 
K

Keith Thompson

madhawi said:
i want to know that on what situation memory leakage happan

Memory is allocated but not deallocated.
and what
is the solution to solve the problem of memory leakage.

Deallocate any memory that you allocate.

Memory is allocated by calling malloc() and deallocated by calling
free(). Each chunk of memory allocated by malloc() should be released
by calling free() when you're done with it.

Of course it's not necessarily that simple, but explaining the details
would be equivalent to explaining how to program.
 
K

Keith Thompson

madhawi said:
I am asking in C++. I use my application on Window2000.
[...]

Pay very close attention to the following.

Please do not top-post. Read the following web pages to understand
what "top-posting" is, and why you shouldn't do it.

http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

You are asking about C++. This is comp.lang.c. C and C++ are two
different languages. If you have questions about C++, comp.lang.c++
is the place to ask. This is not.
 
S

santosh

madhawi said:
I am asking in C++. I use my application on Window2000.

[top-post snipped]

If it's a generic C++ question post to comp.lang.c++. If your problem
involves platform specific extensions, it might be better to post to a
more platform specific group like comp.os.ms-windows.programmer.win32.
 
J

John den Haan

madhawi schreef:
i m working on a large project. and i used free() for memory. but
still i get problem. when i removed the line from where i m getting
memory leakage, then i get another problem, loss of information.

You may be freeing the wrong pointer. In other words: you may be freeing
useful data? There is absolutely no guarantee that a free'd block of
memory still contains any useful data.

--

Cheers,

John den Haan
joDhn[dot]haEan[at]chLello[dot]nl

Remove capital 'DEL' from above addy to obtain e-mail address
 
D

Daniel Rudy

At about the time of 2/20/2007 8:31 PM, madhawi stated the following:

Please don't top-post.
I am asking in C++. I use my application on Window2000.

This group is C only, not C++, not Apple C, not coca, not PL1, fortran,
pascal, or anything else. C only. Since your question is a C++
question, post your question in comp.lang.c++ instead of here.

As for Windows 2K, you'll need to post in one of the
comp.os.ms-windows.programmer groups, or another group that supports
your platform. You may also try one of Microsoft's programming forums
on their developer's network (requires subscription though).

As for a memory leak, the best way to avoid it is for every call to
malloc that you make, there should also be a corresponding free
statement. If you destroy the contents of a pointer before calling
free, then that memory remains allocated but unaccessible since you no
longer know where it is. So as your program keeps executing the same
piece of code, the memory usage will get larger and larger until you
eventually run out. What happens then is implementation specific.

I do know that on some implementations if you call free twice, you will
get a warning (mainly on the unix style platforms). But, IIRC, call
free on a block of memory that is already free results in undefined
behavior.


--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

memory leakage problem 2
could this generate memory leakage? 1
Handing initialization failures 12
memory leakage 7
memory leakage 2
What is memory leakage 18
Self healthcheck 8
Compilation error 4

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top