> class UnmanagedClass
> {
> public:
> gcroot<System:: Xml::XmlDocumen t *>pMc;
>
> UnmanagedClass( System::Xml::Xm lDocument * in)
> {
> pMc = in;
> }
>
> ~ UnmanagedClass( )
> {
> delete pMc;
> }
When I try to compile this code, I get the error:
\x.cpp(92): error C3841: illegal delete expression: managed type 'System::Xml::X mlDocument' does not have a destructor defined
If I remove the delete pMc from the destructor, the code compiles, however memory is leaked if I create a new unmanaged object, (from an unmanaged class) and then delete the unmanaged object. I have tried calling garbage collect from managed code after I have created an deleted the unmanaged object, and there is still a lot of memory that does not get freed. Does anyone have any ideas on why I'm getting the error? Or maybe have an idea for a workaround?
Thanks for your time!!
2 1988 RedSon 5,000
Recognized Expert Expert
> class UnmanagedClass
> {
> public:
> gcroot<System:: Xml::XmlDocumen t *>pMc;
>
> UnmanagedClass( System::Xml::Xm lDocument * in)
> {
> pMc = in;
> }
>
> ~ UnmanagedClass( )
> {
> delete pMc;
> }
When I try to compile this code, I get the error:
\x.cpp(92): error C3841: illegal delete expression: managed type 'System::Xml::X mlDocument' does not have a destructor defined
If I remove the delete pMc from the destructor, the code compiles, however memory is leaked if I create a new unmanaged object, (from an unmanaged class) and then delete the unmanaged object. I have tried calling garbage collect from managed code after I have created an deleted the unmanaged object, and there is still a lot of memory that does not get freed. Does anyone have any ideas on why I'm getting the error? Or maybe have an idea for a workaround?
Thanks for your time!!
I'm a little confused. Presumably when you are creating a pointer to an object some other bit of code is going to do the creation of that object and then pass it to your application. So if someone else is doing the creation why are you doing the deletion? Other then that I have no idea how to destroy an XmlDocument object. The help on MSDN is not very useful, except to perhaps say use the removeAll method and then set your pointer to null. That way if nothing is pointing to that object anymore the GC should then take care of it. The problem is GC may take a little while to get to it.
I'm a little confused. Presumably when you are creating a pointer to an object some other bit of code is going to do the creation of that object and then pass it to your application. So if someone else is doing the creation why are you doing the deletion? Other then that I have no idea how to destroy an XmlDocument object. The help on MSDN is not very useful, except to perhaps say use the removeAll method and then set your pointer to null. That way if nothing is pointing to that object anymore the GC should then take care of it. The problem is GC may take a little while to get to it.
What I'm trying to do is to delete the pointer so that reference to the object goes away. Garbage collection isn't picking up the object, so I'm trying to find out why.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jonathan Ames |
last post by:
Moving to C++ from Java, I'm still confused by some aspects of memory
cleanup operations.
For example, let's say I have a class MovingObject which maintains a
pointer to another class MovementAlgorithm.
MovingObject has a method
SetMovementAlgorithm(MovementAlgorithm* movementAlgorithm)
if the body of this method reads
|
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...
|
by: Arnd Boettcher |
last post by:
How can I invoke the Visual studio C++ compiler by command
line?
Any advices are welcome.
|
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...
|
by: MQ |
last post by:
Hi all
I am just wondering how most people implement cleanup in C functions.
In particular, if the function opens a number of resources, these need
to be released properly should an error occur at any point in the
function (as well as at the end if successful). C++ has exceptions,
the only way I can see to do this neatly in C is to use goto
statements. Is my method of implementing cleanup good, or are their
better ways. Here is an...
| |
by: rabidus |
last post by:
> class UnmanagedClass
> {
> public:
> gcroot<ManagedClass *>pMc;
>
> UnmanagedClass(ManagedClass * in)
> {
> pMc = in;
> }
>
|
by: =?Utf-8?B?QWw=?= |
last post by:
I am storing an array of strings in an unmanaged MFC class using gcroot as
follows:
gcroot<array<System::String^>^m_pArr;
Nothing out of the ordinary there. However, if I try to use "delete m_pArr"
in the code in order to deterministically delete it, I get the following
error in VS05:
error C2440: 'delete' : cannot convert from 'gcroot<T>' to 'void *'
If I use the same with something other than an array i.e. using gcroot and
|
by: Peter Michaux |
last post by:
I just ran some circular memory leak tests in IE6, O9, S3, FF2 and it
seems to me they all benefit from doing the same kind of circular
memory leak cleanup that IE requires.
My tests were very similar to Richard Cornford's which are very easy
to set up and watch run.
<URL: http://groups.google.com/group/comp.lang.javascript/msg/e723d3324aaa4127>
On my machine, O, S, and FF all level off at around 38MB of RAM while
|
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...
|
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...
|
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...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |