473,387 Members | 1,464 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 allocation problems

In my project I have a class which I create an instance of, into a pointer
using the 'new' keyword.

Inside 'class1' I allocate memory (using malloc) for a string in the
constructor and everything works fine. When I try to destroy the instance
using the corresponding 'delete' keyword, the code goes to 'class1'
destructor where I try to free the memory (using free) allocated by the
constructor. However I get a debug error.

Am I getting the error because when I destroy the instance of 'class1' the
memory allocated by the constructor is already freed, and therefore I am
trying to free free memory, or is there something else at work?
Jul 19 '05 #1
3 2333
before you free the memory, please check that it is not a null pointer.

Jasn

"Kieran Simpson" <st************@hotmail.com> дÈëÏûÏ¢ÐÂÎÅ
:kP***************@nnrp1.ozemail.com.au...
In my project I have a class which I create an instance of, into a pointer


Jul 19 '05 #2

"Jason Xie" <ja******@gdnt.com.cn> wrote in message
news:bd**********@bcarh8ab.ca.nortel.com...
before you free the memory, please check that it is not a null pointer.


Freeing a NULL pointer does not cause any problems.
OP should post some real code to demonstarate the problem.
Jul 19 '05 #3

"Kieran Simpson" <st************@hotmail.com> wrote in message
news:kP***************@nnrp1.ozemail.com.au...
In my project I have a class which I create an instance of, into a pointer
using the 'new' keyword.

Inside 'class1' I allocate memory (using malloc) for a string in the
constructor and everything works fine. When I try to destroy the instance
using the corresponding 'delete' keyword, the code goes to 'class1'
destructor where I try to free the memory (using free) allocated by the
constructor. However I get a debug error.

Am I getting the error because when I destroy the instance of 'class1' the
memory allocated by the constructor is already freed, and therefore I am
trying to free free memory, or is there something else at work?


Maybe, maybe not. Hard to tell without seeing any code.

POST SOME CODE, jeez.

john
Jul 19 '05 #4

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

Similar topics

4
by: Maurice | last post by:
Hi there, I'm experiencing big memory problems on my webserver. First on an old RedHat 7.2 system, now on an other fresh installed Suse 8.2 system: Linux version 2.4.20-4GB...
18
by: Tron Thomas | last post by:
Given the following information about memory management in C++: ----- The c-runtime dynamic memory manager (and most other commercial memory managers) has issues with fragmentation similar to a...
5
by: DLPnet | last post by:
Hello, I m working on Windows and Mac in C++. My application uses a lot of memory since it s dealing with a lot of images. So I load images in a cache when needed and if I haven t enough...
4
by: PaulR | last post by:
Hi, We have a Server running SLES 8 and 3GB memory, with 1 DB2 instance and 2 active Databases. General info... DB2level = "DB2 v8.1.0.72", "s040914", "MI00086", and FixPak "7" uname -a =...
15
by: berthelot samuel | last post by:
Hi, I'm trying to develop an application for modeling 3D objects from Bezier patches, but I have a memory allocation problem. Here are my structures: typedef struct _vector3 { union { struct...
7
by: Dan Nilsen | last post by:
Hi! I'm writing a small piece of software that basically runs on an embedded system with a Power-PC cpu. This runs on a stripped down version of Linux - Busybox. As I'm writing a piece of...
3
by: Florin | last post by:
Hi all, I have a problem related to memory grow on a server application which is basically stateless (I have some static info loaded). The client accesses this server using remoting and it has...
3
by: ranjeetasharma81 | last post by:
Hi all, I have a big C-cod, in which there are lots of dynamic memory allocation used. I want to replace dynamic memroy allocation by static arrays. The following are the problems that i am...
34
by: jacob navia | last post by:
Suppose that you have a module that always allocates memory without ever releasing it because the guy that wrote it was lazy, as lazy as me. Now, you want to reuse it in a loop. What do you do?...
12
by: David Given | last post by:
I have a situation where I need to be able to allocate chunks on unmapped virtual memory. Because the memory I'm allocating isn't mapped, I can't use a normal memory allocator, as most of them...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.