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

.net visual c++ 2003 gcroot cleanup/memory leak question

> class UnmanagedClass
> {
> public:
> gcroot<System::Xml::XmlDocument *>pMc;
>
> UnmanagedClass(System::Xml::XmlDocument * 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::XmlDocument' 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!!
Feb 1 '07 #1
2 1969
RedSon
5,000 Expert 4TB
> class UnmanagedClass
> {
> public:
> gcroot<System::Xml::XmlDocument *>pMc;
>
> UnmanagedClass(System::Xml::XmlDocument * 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::XmlDocument' 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.
Feb 2 '07 #2
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.
Feb 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
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...
17
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...
9
by: Arnd Boettcher | last post by:
How can I invoke the Visual studio C++ compiler by command line? Any advices are welcome.
7
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...
69
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...
5
by: rabidus | last post by:
> class UnmanagedClass > { > public: > gcroot<ManagedClass *>pMc; > > UnmanagedClass(ManagedClass * in) > { > pMc = in; > } >
6
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...
6
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...
22
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.