By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 811 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

memory leakage

P: n/a
i want to know that on what situation memory leakage happan and what
is the solution to solve the problem of memory leakage.

Feb 21 '07 #1
Share this Question
Share on Google+
14 Replies


P: n/a
On Feb 20, 7:30 pm, "madhawi" <madhaw...@gmail.comwrote:
i want to know that on what situation memory leakage happan
When you have more calls to malloc() and calloc() than you do to
free().
and what
is the solution to solve the problem of memory leakage.
Have one call to free() for each call to calloc() or malloc() that
your program makes.

If you want to fix something that's broken, look here:
https://buildsecurityin.us-cert.gov/...oding/311.html
Feb 21 '07 #2

P: n/a
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.
user923005 wrote:
On Feb 20, 7:30 pm, "madhawi" <madhaw...@gmail.comwrote:
i want to know that on what situation memory leakage happan

When you have more calls to malloc() and calloc() than you do to
free().
and what
is the solution to solve the problem of memory leakage.

Have one call to free() for each call to calloc() or malloc() that
your program makes.

If you want to fix something that's broken, look here:
https://buildsecurityin.us-cert.gov/...oding/311.html
Feb 21 '07 #3

P: n/a
On Feb 21, 8:30 am, "madhawi" <madhaw...@gmail.comwrote:
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/...-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

Feb 21 '07 #4

P: n/a
i am using c++. i used delete and destructor to free the memory. can u
help me this in c++, please.
raxitsheth2...@yahoo.co.in wrote:
On Feb 21, 8:30 am, "madhawi" <madhaw...@gmail.comwrote:
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/...-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
Feb 21 '07 #5

P: n/a
madhawi wrote:

Please don't top-post.
user923005 wrote:
>>On Feb 20, 7:30 pm, "madhawi" <madhaw...@gmail.comwrote:
>>>i want to know that on what situation memory leakage happan

When you have more calls to malloc() and calloc() than you do to
free().
>>>and what
is the solution to solve the problem of memory leakage.

Have one call to free() for each call to calloc() or malloc() that
your program makes.

If you want to fix something that's broken, look here:
https://buildsecurityin.us-cert.gov/...oding/311.html

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.

--
Ian Collins.
Feb 21 '07 #6

P: n/a
madhawi wrote:
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.

--
Ian Collins.
Feb 21 '07 #7

P: n/a
"madhawi" <ma*******@gmail.comwrites:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 21 '07 #8

P: n/a
I am asking in C++. I use my application on Window2000.
Ian Collins wrote:
madhawi wrote:
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.

--
Ian Collins.
Feb 21 '07 #9

P: n/a
madhawi wrote:
I am asking in C++. I use my application on Window2000.
When you do, don't forget not to top post!
Ian Collins wrote:
>>madhawi wrote:
>>>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.

--
Ian Collins.
Feb 21 '07 #10

P: n/a
"madhawi" <ma*******@gmail.comwrites:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 21 '07 #11

P: n/a
madhawi wrote:
Ian Collins wrote:
madhawi wrote:
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.

I am asking in C++. I use my application on Window2000.
this link helped me
http://www.kbcafe.com/articles/Memory.Leaks.pdf

it is actually buggy, but provided enough clues for me to find leaks
in a
large win32 app
--
Nick Keighley

Feb 21 '07 #12

P: n/a

madhawi wrote:
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.

Feb 21 '07 #13

P: n/a
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
Feb 23 '07 #14

P: n/a
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.
Ian Collins wrote:
>madhawi wrote:
>>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.

--
Ian Collins.
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
Feb 23 '07 #15

This discussion thread is closed

Replies have been disabled for this discussion.