> class UnmanagedClass
> {
> public:
> gcroot<ManagedC lass *>pMc;
>
> UnmanagedClass( ManagedClass * in)
> {
> pMc = in;
> }
>
> ~ UnmanagedClass( )
> {
> delete pMc;
> }
I took this from another post, but I have a question on a very similar topic. When I try to run the following code, and call the destructor on UnmanagedClass, it tells me that there is no destructor defined for ManagedClass. (I'm substituting System::XML::Xm lDocument for ManagedClass)
I am having a memory leak because I am unable to destroy the managed object created in the unmanaged class. Any help would be GREATLY appreciated. Thanks!!!!
5 2464
I should say, I think the problem comes from the fact that I'm not destroying the gcroot pointer, which has a reference to the managed object, and so the managed object is persisting in memory, even when the unmanaged class goes out of scope. Thanks again !!
> class UnmanagedClass
> {
> public:
> gcroot<ManagedC lass *>pMc;
>
> UnmanagedClass( ManagedClass * in)
> {
> pMc = in;
> }
>
> ~ UnmanagedClass( )
> {
> delete pMc;
> }
I took this from another post, but I have a question on a very similar topic. When I try to run the following code, and call the destructor on UnmanagedClass, it tells me that there is no destructor defined for ManagedClass. (I'm substituting System::XML::Xm lDocument for ManagedClass)
I am having a memory leak because I am unable to destroy the managed object created in the unmanaged class. Any help would be GREATLY appreciated. Thanks!!!!
Ganon11 3,652
Recognized Expert Specialist
It doesn't look like pMc is actually a pointer, but some class holding a pointer - you may consider writing a deconstructor for gcroot.
Thank you very much for your quick reply!!
Yes, you are correct in that the gcroot object holds a pointer, and isn't a pointer itself. However, in gcroot.h (visual c++ code from microsoft), there is already a destructor defined for gcroot objects. However, when I I try to compile with the call:
delete pMc;
The compiler gives an error saying "there is no destructor for managed class ManagedClass"
Does anyone have any ideas as to why I'm getting that message, and any possible solutions to fix the leak that I am encountering? Thanks!
Ganon11 3,652
Recognized Expert Specialist
Is ManagedClass a class that you are writing and modifying? If so, is there a deconstructor for it?
Your gcroot pointer's deconstructor may be trying to delete the ManagedClass pointer it has, but is unable to because managedClass has no deconstructor.
ManagedClass is a visual studio .net 2003 class (System::Xml::X mlDocument to be exact), and there is no deconstructor for that type.
Normally the resources are freed up by the garbage collector for that type. However, I am using gcroot, in unmanaged code (on the native heap, outside the scope of the garbage collector), to get a pointer to a location on the managed heap, so I can instantiate a managed object.
The problem is that when the unmanaged class that contains the gcroot pointer is destroyed, there is some memory that is being leaked, presumably that which the gcroot pointer was pointing to, and I'm not sure how to remedy the problem. I'm almost certain it has something to do with the inability to delete the gcroot pointer.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: igal.ioffe |
last post by:
Hi All,
I've run into a problem, converting a native project
into mixed mode, where usage of gcroot point in mixed mode
causes a fatal CLR engine exception.
Here is a tiny code extract:
------------------ mixeddll.cpp ----------
#include <vcclr.h>
|
by: Gerhard Menzl |
last post by:
Has anyone ever tried to sort a Standard Library container of gcroots? I
have run into the problem that somewhere deep in the Library logic (in
line 338 of <memory>, to be precise) the destructor of a class
_Temp_iterator tries to obtain the address of a gcroot, but fails
because gcroot::operator& is private.
--
Gerhard Menzl
#dogma int main ()
|
by: Rob Haynes |
last post by:
I have a DLL with vanilla C functions implemented. I'd like these functions
to become wrappers for a managed object. So, I was thinking that the first
call would save a pointer statically to the managed object that future calls
could use. I found this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vcconconvertingmanagedextensionsforcprojectsfrompureintermediatelanguagetomixedmode.asp
and have implemented it...
|
by: Maxwell |
last post by:
Hello,
Im using MC++ VS.NET 2003 and am quite confused with with gcroot
template and its use. The issue I am confused about is the need to (or
not) delete a pointer to a managed object that you have created using
gcroot. For example(from Managed VC++ 2003 Step by Step by Microsoft
Press p510):
class UnmanagedClass
{
|
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<System::Xml::XmlDocument *>pMc;
>
> UnmanagedClass(System::Xml::XmlDocument * 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: =?Utf-8?B?RmFiaWFu?= |
last post by:
Hello,
I have a class hierarchy distributed over 3 native C++ dlls. The base class
has a .NET Windows.Form for status output via a gcroot<>.
The gcroot is declared private - the sub classes only have access via a
protected "print"-method.
I need the different dlls as the sub classes implement the base class's pure
virtual methods using different technologies.
To use the native classes from outside their dlls I use the...
|
by: Bob Altman |
last post by:
Hi all,
In C++/CLI (VS 2005) I have a C++ module compiled with /clr that contains a
module-level gcroot variable:
static gcroot<MyList^m_myList = gcnew MyList;
In the above statement, MyList is a managed class that inherits from
Generic::List. I want to iterate through m_myList like this:
|
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: 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,...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: 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...
|
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: 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...
| |