473,386 Members | 1,835 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,386 software developers and data experts.

deleteall

bob
why can't there be a deleteall keyword in c++ that
deletes all the memory previously allocated by
the new keyword?

wouldn't this solve a lot of memory leak issues?

Apr 17 '06 #1
13 2327

bo*@coolgroups.com skrev:
why can't there be a deleteall keyword in c++ that
deletes all the memory previously allocated by
the new keyword?

wouldn't this solve a lot of memory leak issues?


No - why do you believe so? All memory allocated would be invalid
suddenly and there would not really be any option but to terminate the
program (which typically releases all resources anyway).

/Peter

Apr 17 '06 #2
bob
it would be called before termination usually. i don't think
termination typically releases all resources.

Apr 17 '06 #3

bo*@coolgroups.com wrote:
it would be called before termination usually. i don't think
termination typically releases all resources.


deleteall doesn't make sense because it doesn't control its behaviors
itself.
Modern OS' memory management can handle the release of memory resource
after terminating a process. Memory leakage is fatal while the process
is running so the programmer should avoid the memory leakage.

Apr 17 '06 #4
bo*@coolgroups.com wrote:
why can't there be a deleteall keyword in c++ that
deletes all the memory previously allocated by
the new keyword?

wouldn't this solve a lot of memory leak issues?


If a program makes a series of memory allocations of equal size, then
it can use a memory "pool" (such as boost's "pool" library) so that all
of the allocations are fulfilled from the same block of reserved
memory. A program can then deallocate the entire pool and thereby free
all of the pooled allocations at once. And indeed this approach is not
only very efficient but also eliminates the chance that any of pooled
allocations could leak.

Unfortunately, relatively few applications actually have memory
allocation patterns that could be implemented by a pool. Instead most
programs create and delete objects in such a way that their life spans
overlap; as a consequence, a typical program is constantly allocating
and deallocating memory in various sizes and without adhering to any
discernable pattern. Therefore there is never a point in most programs'
execution in which all allocations up to that point could safely be
freed at once. So while your idea certainly has merit, it is applicable
only to relatively few programs.

Greg

Apr 17 '06 #5
bo*@coolgroups.com wrote:
it would be called before termination usually. i don't think
termination typically releases all resources.


Most modern general purpose operating systems do certainly release
allocated memory upon process termination.

Apr 17 '06 #6
REH

dan2online wrote:
bo*@coolgroups.com wrote:
it would be called before termination usually. i don't think
termination typically releases all resources.


deleteall doesn't make sense because it doesn't control its behaviors
itself.
Modern OS' memory management can handle the release of memory resource
after terminating a process.


Modern hosted systems typically do so. Most modern embedded OSes do
not.

REH

Apr 17 '06 #7
bob wrote:
why can't there be a deleteall keyword in c++ that
deletes all the memory previously allocated by
the new keyword?

wouldn't this solve a lot of memory leak issues?


The point of delete is "deterministic destruction". Under RAII (look it up),
an object's destructor should have useful side effects.

A complete program should have some 'new'-ed object that should last for the
life of the program, and should have some 'new'-ed objects that should come
and go. (And most objects should either be on the stack, or should be
members of other objects. So most object should not be created by 'new'.)

When a program ends, many OSs will free all its resources. (And many will
not. These OSs are often referred to as "embedded" these days.) These OSs
will not call destructors for all leaked objects.

The point of C++'s memory allocation system is to lead programmers to build
a coherent object model where objects own sub-objects, and manage their
lifespans. A 'deleteall' keyword will not improve these designs.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 17 '06 #8
REH

Phlip wrote:
When a program ends, many OSs will free all its resources. (And many will
not. These OSs are often referred to as "embedded" these days.)
Though, not for that reason.
These OSs will not call destructors for all leaked objects.

I don't believe there is *any* OS that will call the destructors for an
application, even though they may reclaim the memory.

REH

Apr 17 '06 #9

REH wrote:
dan2online wrote:
bo*@coolgroups.com wrote:
it would be called before termination usually. i don't think
termination typically releases all resources.


deleteall doesn't make sense because it doesn't control its behaviors
itself.
Modern OS' memory management can handle the release of memory resource
after terminating a process.


Modern hosted systems typically do so. Most modern embedded OSes do
not.


How embedded systems do will depend on MMU hardware and OS which
supports MMU.

Apr 17 '06 #10
dan2online wrote:
Modern hosted systems typically do so.Â*Â*MostÂ*modernÂ*embeddedÂ*OSesÂ*do
not.


How embedded systems do will depend onÂ*Â*MMUÂ*hardwareÂ*andÂ*OSÂ*which
supports MMU.


Can we make a guideline out of "the smaller the embedded system, the lower
the chances it will free resources that you leak"?

The point is C++ enables very small embedded systems by allowing programs to
clean up their resources the most efficient way - by releasing them in
destructors.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 17 '06 #11
REH

dan2online wrote:
REH wrote:
dan2online wrote:
bo*@coolgroups.com wrote:
> it would be called before termination usually. i don't think
> termination typically releases all resources.

deleteall doesn't make sense because it doesn't control its behaviors
itself.
Modern OS' memory management can handle the release of memory resource
after terminating a process.


Modern hosted systems typically do so. Most modern embedded OSes do
not.


How embedded systems do will depend on MMU hardware and OS which
supports MMU.


That can be said for any OS.

REH

Apr 17 '06 #12
"Greg" <gr****@pacbell.net> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
: bo*@coolgroups.com wrote:
: > why can't there be a deleteall keyword in c++ that
: > deletes all the memory previously allocated by
: > the new keyword?
: >
: > wouldn't this solve a lot of memory leak issues?
:
: If a program makes a series of memory allocations of equal size, then
: it can use a memory "pool" (such as boost's "pool" library) so that all
: of the allocations are fulfilled from the same block of reserved
: memory.
NB: there is no need for all objects in the pool to be of equal size.

: A program can then deallocate the entire pool and thereby free
: all of the pooled allocations at once. And indeed this approach is not
: only very efficient but also eliminates the chance that any of pooled
: allocations could leak.
:
: Unfortunately, relatively few applications actually have memory
: allocation patterns that could be implemented by a pool. Instead most
: programs create and delete objects in such a way that their life spans
: overlap; as a consequence, a typical program is constantly allocating
: and deallocating memory in various sizes and without adhering to any
: discernable pattern. Therefore there is never a point in most programs'
: execution in which all allocations up to that point could safely be
: freed at once. So while your idea certainly has merit, it is applicable
: only to relatively few programs.
Well: pooled allocations were an integral part of the Objective C
library on NeXT and MacOSX, and I think the feature is well taken
advantage of.
For example, a web browser could have one pool per rendered document.
Several apps could have one pool per document.

The Apache web server also heavily uses a memory pooling system,
they have some C libraries to support that.

Also, any function that allocates temporary data as part of its
processing could use a memory pool. Although, in C++, we tend to
use RAII and stack-based objects instead.
But another issue that needs to be addressed when using memory
pools (just as for garbage collection), is how to deal with
destructors that may have to be called (to release non-memory
resources). This typically requires some system to register
destructors, and ends up being more complex than classic RAII
with stack-based objects.
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com
Apr 17 '06 #13

bo*@coolgroups.com wrote:
why can't there be a deleteall keyword in c++ that
deletes all the memory previously allocated by
the new keyword?


Because you can't get the order right.

HTH,
Michiel Salters

Apr 20 '06 #14

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

Similar topics

0
by: Steve Drake | last post by:
All, I have the following code : void Test() { DropDirectory DropDir=new DropDirectoryClass(); IMessages Messages= DropDir.GetMessages(null); foreach (IMessage Message in Messages)
5
by: matt dittman | last post by:
I have created a windows service that reads emails from a drop directory and moves them to the appropriate mail folder every 15 seconds. I can move, rename and delete the files as needed, up...
4
by: Luiz Ragazzi | last post by:
Please, anyone can help on this: I need to call a method from my class but I need the information type at run time..as I know, I have to use GetType method of the object class. Any idea how to...
0
by: Tony Johansson | last post by:
Hello! I have two classes called Handle which is a template class and a class Integer which is not a template class. The Integer class is just a wrapper class for a primitive int with some...
10
by: Tony Johansson | last post by:
Hello Experts!! This class template and main works perfectly fine. I have this class template called Handle that has a pointer declared as T* body; As you can see I have a reference counter in...
1
by: Tony Johansson | last post by:
This class template and main works perfectly fine. But could be better. I have this class template called Handle that has a pointer declared as T* body; As you can see I have a reference counter...
4
by: Michael Domenic DiBernardo | last post by:
I posted this on comp.std.c++ because it seemed a more appropriate question for that forum, but I'm more or less in a hurry and so I decided to toss it out here as well: How might I declare a...
6
by: dtschoepe | last post by:
Hi all, Working on homework again... I've got a weird problem, I've been banging my head against the wall on what is causing it. I have a pointer to a typdef named Person. At one point in the...
9
by: danil52 | last post by:
I have dynamic memory allocation in my constructor and deallocation in my destructor. However if there is exception being thrown in constructor, the destructor does not get called and memory leaks...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.