473,757 Members | 6,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can anybody help me about the memory leak

Eg. we have the class hiaerarchy Point inherit Point3D

class Point
{
public:
Point(int a=0,char* b=0):x(a),y(b){ }
private:
int x;
char* y;
};

class Point3D: public Point
{
public:
Point3D(char*c= 0):z(c){}
private:
char* z;
}

Once we instatiate an array like this:
Point* pPointArray = new Point3D[10];
delete[] pPointArray;

why this will cause memory leak?
will delete recursively invoke Point3D's destructor.

Thanks indeed
Ge Chunyuan

Jul 24 '07 #1
7 1246
On Jul 24, 9:16 am, Ge Chunyuan <hhy...@gmail.c omwrote:
Eg. we have the class hiaerarchy Point inherit Point3D

class Point
{
public:
Point(int a=0,char* b=0):x(a),y(b){ }
private:
int x;
char* y;

};

class Point3D: public Point
{
public:
Point3D(char*c= 0):z(c){}
private:
char* z;

}
missing semicolon
>
Once we instatiate an array like this:
Point* pPointArray = new Point3D[10];
delete[] pPointArray;

why this will cause memory leak?
will delete recursively invoke Point3D's destructor.
1. The base class destructor must be virtual if you wish to delete a
derived class object through the base class pointer.

2. Deleting array of derived class objects through base class pointer
is undefined.

3. 'Never Treat Arrays Polymporphicall y' : More Effective C++ (Point
3).

-N

Jul 24 '07 #2
jg
On Jul 23, 9:16 pm, Ge Chunyuan <hhy...@gmail.c omwrote:
Eg. we have the class hiaerarchy Point inherit Point3D

class Point
{
public:
Point(int a=0,char* b=0):x(a),y(b){ }
private:
int x;
char* y;

};

class Point3D: public Point
{
public:
Point3D(char*c= 0):z(c){}
private:
char* z;

}

Once we instatiate an array like this:
Point* pPointArray = new Point3D[10];
delete[] pPointArray;

why this will cause memory leak?
will delete recursively invoke Point3D's destructor.

Thanks indeed
Ge Chunyuan
To declare an array of Point3D, the default ctor Point3D::Point3 D()
as well as Point::Point() must be defined.

Can your code be compiled successfully ?

JG

Jul 24 '07 #3
On Jul 24, 10:00 am, jg <jgu...@gmail.c omwrote:
On Jul 23, 9:16 pm, Ge Chunyuan <hhy...@gmail.c omwrote:
Eg. we have the class hiaerarchy Point inherit Point3D
class Point
{
public:
Point(int a=0,char* b=0):x(a),y(b){ }
private:
int x;
char* y;
};
class Point3D: public Point
{
public:
Point3D(char*c= 0):z(c){}
private:
char* z;
}
Once we instatiate an array like this:
Point* pPointArray = new Point3D[10];
delete[] pPointArray;
why this will cause memory leak?
will delete recursively invoke Point3D's destructor.
Thanks indeed
Ge Chunyuan

To declare an array of Point3D, the default ctor Point3D::Point3 D()
as well as Point::Point() must be defined.
Point::point(in t =0, char* = 0) can act as Point::Point() since all
its arguments have default values.

Can your code be compiled successfully ?
It cannot, simply because there is a missing semicolon after
definition of Point3D. Otherwise it does.
JG
-N

Jul 24 '07 #4
On Jul 24, 1:53 pm, Neelesh Bodas <neelesh.bo...@ gmail.comwrote:
On Jul 24, 10:00 am, jg <jgu...@gmail.c omwrote:
On Jul 23, 9:16 pm, Ge Chunyuan <hhy...@gmail.c omwrote:
Eg. we have the class hiaerarchy Point inherit Point3D
class Point
{
public:
Point(int a=0,char* b=0):x(a),y(b){ }
private:
int x;
char* y;
};
class Point3D: public Point
{
public:
Point3D(char*c= 0):z(c){}
private:
char* z;
}
Once we instatiate an array like this:
Point* pPointArray = new Point3D[10];
delete[] pPointArray;
why this will cause memory leak?
will delete recursively invoke Point3D's destructor.
Thanks indeed
Ge Chunyuan
To declare an array of Point3D, the default ctor Point3D::Point3 D()
as well as Point::Point() must be defined.

Point::point(in t =0, char* = 0) can act as Point::Point() since all
its arguments have default values.
Can your code be compiled successfully ?

It cannot, simply because there is a missing semicolon after
definition of Point3D. Otherwise it does.
You are so funny.
JG

-N

Jul 24 '07 #5
On Jul 24, 2:09 pm, "1983...@gmail. com" <1983...@gmail. comwrote:
On Jul 24, 1:53 pm, Neelesh Bodas <neelesh.bo...@ gmail.comwrote:
On Jul 24, 10:00 am, jg <jgu...@gmail.c omwrote:
On Jul 23, 9:16 pm, Ge Chunyuan <hhy...@gmail.c omwrote:
Eg. we have the class hiaerarchy Point inherit Point3D
class Point
{
public:
Point(int a=0,char* b=0):x(a),y(b){ }
private:
int x;
char* y;
};
class Point3D: public Point
{
public:
Point3D(char*c= 0):z(c){}
private:
char* z;
}
Once we instatiate an array like this:
Point* pPointArray = new Point3D[10];
delete[] pPointArray;
why this will cause memory leak?
will delete recursively invoke Point3D's destructor.
Thanks indeed
Ge Chunyuan
To declare an array of Point3D, the default ctor Point3D::Point3 D()
as well as Point::Point() must be defined.
Point::point(in t =0, char* = 0) can act as Point::Point() since all
its arguments have default values.
Can your code be compiled successfully ?
It cannot, simply because there is a missing semicolon after
definition of Point3D. Otherwise it does.

You are so funny.
JG
-N

But I want to know where it will leak? I have no found any new
operation except Point = new ...
Forgive me my shallow about memory leak. Thank you.

Jul 24 '07 #6
On Jul 24, 10:16 am, "Alf P. Steinbach" <al...@start.no wrote:
* Ge Chunyuan:
and I believe the C++ committee pages link to
the latest draft (which has many things not yet officially standard).
I'm not sure off hand if you can access this without being a
member or not. But if you can, it's probably the better
solution. For the most, the changes are marked, so you can
still see what the official standard said. (This is not
necessarily true when the change is the introduction of an
entire new section, and there's no indication, for example, that
§23.4 doesn't exist at all in the currently official version.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 24 '07 #7
On 2007-07-24 09:18:26 -0400, James Kanze <ja*********@gm ail.comsaid:
On Jul 24, 10:16 am, "Alf P. Steinbach" <al...@start.no wrote:
>* Ge Chunyuan:
and I believe the C++ committee pages link to
the latest draft (which has many things not yet officially standard).

I'm not sure off hand if you can access this without being a
member or not. But if you can, it's probably the better
solution. For the most, the changes are marked, so you can
still see what the official standard said. (This is not
necessarily true when the change is the introduction of an
entire new section, and there's no indication, for example, that
§23.4 doesn't exist at all in the currently official version.)
The change bars show changes from the previous draft, not from the
current standard. That includes new and removed sections, but, as with
all the other changes, only for the first revision where the change
occurred.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Jul 25 '07 #8

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

Similar topics

8
3413
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? In nut shell, what is/are the realtion/s between the Memory Leak and Memory Corruption. Juts Theoritical Assumtion below:
17
4814
by: José Joye | last post by:
Hi, I have implemented a Service that is responsible for getting messages from a MS MQ located on a remote machine. I'm getting memory leak from time to time (???). In some situation, it is easier to reproduce (e.g.: remote machine not available). After about 1 day, I get a usage of 300MB of memory. I have used .NET Memory Profiler tool to try to see where the leak is located. For all the leaky instances, I can see the following (I...
4
6093
by: Don Nell | last post by:
Hello Why is there a memory leak when this code is executed. for(;;) { ManagementScope scope = new ManagementScope(); scope.Options.Username="username"; scope.Options.Password="password"; scope.Path.Path=@"\\pc\root\cimv2";
20
8119
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex matches are called within a loop (like if or for). E.g. for(int i = 0; i < 10; i++) { Regex r = new Regex();
23
4566
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
8
8552
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of each object within my JS app to help locate my problem? Thanks
7
6935
by: Salvador | last post by:
Hi, I am using WMI to gather information about different computers (using win2K and win 2K3), checking common classes and also WMI load balance. My application runs every 1 minute and reports the status of the machines. Upon we follow the .NET object lifetime recommendations the application is constantly consuming more memory! The problem is on the ManagementObjectSearch, upon we Dispose the object it seems that is not releasing the...
3
5326
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". Anybody know anything about this? Does *Javascript* leak memeory, or does the *browser* leak memory?
22
9361
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a memory leak someplace. I can not detect the memory leak by running several reports by hand, but when I run tha app as a servrice and process few hundred reports there is significant memory leak. The application can consume over 1GB of memory where it...
0
9489
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10072
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.