473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Memory leak with new / delete

We have a multithreaded program that uses new and delete. We have not
over-ridden these operators. We're currently experiencing leaking for
the program.

The programmer that is currently working on it says he read an article
that stated that when new / delete (or new [n] / delete[]) are used
many times / quickly that the memory can sometimes not be freed for
use. This seems like a big problem, but the issues we are having
(threads not purging data correctly even though they seem to be
allocated and deleted via new / delete properly) seem to support this.

I was wondering if anyone else had heard of this article and whether
there was any truth behind new / delete having issues with short use on
large data?

Thanks,
Josh McFarlane

Jul 23 '05 #1
4 1338
Darsant wrote:
[...]
I was wondering if [...]
there was any truth behind new / delete having issues with short use on
large data?


Nothing in the language specification supports or goes against this. How
free store is managed behind the scenes is implementation-defined and
often platform-specific. Also, remember that all the tools that "report
memory leaks" do so in some platform-specific manner and often without
considerations of implementation-specific details.

All that should give you a hint to ask either in the newsgroup that deals
with your platform or with your compiler. The only "true" leak is when
memory is allocated (using 'new' or 'new[]') and not freed using 'delete'
or 'delete[]'. If the respective operators are paired in your program,
you've done it correctly AFA C++ _language_ is concerned.

V
Jul 23 '05 #2
Victor Bazarov wrote:
Nothing in the language specification supports or goes against this. How
free store is managed behind the scenes is implementation-defined and
often platform-specific. Also, remember that all the tools that "report
memory leaks" do so in some platform-specific manner and often without
considerations of implementation-specific details.

All that should give you a hint to ask either in the newsgroup that deals
with your platform or with your compiler. The only "true" leak is when
memory is allocated (using 'new' or 'new[]') and not freed using 'delete'
or 'delete[]'. If the respective operators are paired in your program,
you've done it correctly AFA C++ _language_ is concerned.

V


Thanks for the quick response. I was afraid it might be more dependant
upon the compiler. I'll go poke around the Windows / VS newsgroups and
see what they have to say.

Jul 23 '05 #3
Darsant wrote:
Victor Bazarov wrote:
Nothing in the language specification supports or goes against this. How
free store is managed behind the scenes is implementation-defined and
often platform-specific. Also, remember that all the tools that "report
memory leaks" do so in some platform-specific manner and often without
considerations of implementation-specific details.

All that should give you a hint to ask either in the newsgroup that deals
with your platform or with your compiler. The only "true" leak is when
memory is allocated (using 'new' or 'new[]') and not freed using 'delete'
or 'delete[]'. If the respective operators are paired in your program,
you've done it correctly AFA C++ _language_ is concerned.

V

Thanks for the quick response. I was afraid it might be more dependant
upon the compiler. I'll go poke around the Windows / VS newsgroups and
see what they have to say.


Well, that's the standards conformant version of the answer. In fact,
any implementation that leaks memory because you call new/delete "too
often" has major problems. Your leak is almost certainly somewhere else.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #4
Darsant wrote:
We have a multithreaded program that uses new and delete. We have not
over-ridden these operators. We're currently experiencing leaking for
the program.


Allocation algorithms for multi-threaded applications can make tradeoffs
between performance and memory use; if you free memory in one thread, do
you expect another thread to be able to allocate it next? - if so, more
locking is needed than if you only reallocate memory in the thread where
it was first used. On the whole, though, you have to go out of your way
to ask for an "optimised" allocator that might suffer from these
problems; your system's default allocator should have sane, if perhaps
slow, behviour. Have you tried Purify or Valgrind or something like that?

--Phil.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brad Moore | last post by:
Hey All, I need help with debugging some code, if this isn't the correct newsgroup to ask in, disregard this message. I'm having difficulty pinpointing a memory leak in my code, I believe it...
32
by: John | last post by:
Hi all: When I run my code, I find that the memory that the code uses keeps increasing. I have a PC with 2G RAM running Debian linux. The code consumes 1.5G memory by the time it finishes...
6
by: Scott Niu | last post by:
Hi, I have this following simple c++ program, it will produce memory leak ( see what I did below ). My observation also showed that: There will be a mem leak when all the 3 conditions are true:...
9
by: benoit808 | last post by:
I don't have a lot of experience with C++ so I apologize if this is a stupid question. I use Paul Nettle's memory manager (mmgr.cpp) which reports a memory leak but I don't think there's one. Here...
16
by: graham.keellings | last post by:
hi, I'm looking for an open source memory pool. It's for use on an embedded system, if that makes any difference. Something with garbage collection/defragmentation would be nice. It should have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.