473,513 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handle of COM object.

Hi

I am using INCA RTX library which i've added to my project resources.
Then i created an object i need to release it manually. I have found
example in MSND - how to release com object without using Garbace
collector ( because it's simply to slow ). Constuctor of MyResource
which inherits from IDisposable gets one argument - Pointer to an
external unmanaged resource. How to get this Pointer from created com
object?

Thanks
PK

Oct 4 '07 #1
7 3128
Piortekk,

Why do you need to get a pointer for the COM object? Why not just pass
the COM object to the static ReleaseComObject method on the Marshal class?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Piotrekk" <Pi*************@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
Hi

I am using INCA RTX library which i've added to my project resources.
Then i created an object i need to release it manually. I have found
example in MSND - how to release com object without using Garbace
collector ( because it's simply to slow ). Constuctor of MyResource
which inherits from IDisposable gets one argument - Pointer to an
external unmanaged resource. How to get this Pointer from created com
object?

Thanks
PK

Oct 4 '07 #2
Why do you need to get a pointer for the COM object? Why not just pass
the COM object to the static ReleaseComObject method on the Marshal class?
INCA RTX objects are very memory consuming and GC is simply to slow.
I have read this article:
http://msdn2.microsoft.com/en-us/lib...isposable.aspx

MyResource constuctor gets pointer to unmanaged object as a parameter.
Thus i thought i will be able to destroy RTX object manually by
calling MyResource object's Dispose Method.

What do you think?

Oct 4 '07 #3
I am not sure if ReleaseComObject will release com object
independently of GarbageCollector.

Oct 4 '07 #4
If you have a wrapper to a COM object, then calling ReleaseComObject
will decrement the reference count on the com object, and the object should
delete itself when the reference count reaches zero.

If you have a pointer to a COM object (in the form of an IntPtr), then
you can pass that to the Release method on the Marshal class and it will do
the same thing.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Piotrekk" <Pi*************@gmail.comwrote in message
news:11**********************@y42g2000hsy.googlegr oups.com...
>I am not sure if ReleaseComObject will release com object
independently of GarbageCollector.

Oct 4 '07 #5
But there is one problem with ReleaseComObject. It will not release
the memory in a second. When I am finished with COM object and pass it
to ReleaseComObject I am done with the pointer. But the memory will
not be released immediately.
Or maybe I am wrong and memory will be released in a moment?

I am in need of releasing memory right after I stop using COM. When
using few 500 mb resources I really shouldn't wait for GC to collect
it...
As it is written in link i gave you ( MyResource inheriting from
IDisposable ) calling Dispose method should release memory by calling
API function private extern static Boolean CloseHandle(IntPtr handle);
- i haven't tried that yet.

Right now I am a bit confused if ReleaseComObject will release the
memory immidiately.

Oct 4 '07 #6
Piotrekk,

You should only release the unmanaged handles, or decrement the
reference count on the COM object that you are holding when you are done
with it. The wrapper for a COM object will still be in memory (which should
be light), but the COM object itself should be disposed of at that point.

You shouldn't have to call Collect at all, rather, you should be letting
the CLR collect garbage for you.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Piotrekk" <Pi*************@gmail.comwrote in message
news:11**********************@22g2000hsm.googlegro ups.com...
But there is one problem with ReleaseComObject. It will not release
the memory in a second. When I am finished with COM object and pass it
to ReleaseComObject I am done with the pointer. But the memory will
not be released immediately.
Or maybe I am wrong and memory will be released in a moment?

I am in need of releasing memory right after I stop using COM. When
using few 500 mb resources I really shouldn't wait for GC to collect
it...
As it is written in link i gave you ( MyResource inheriting from
IDisposable ) calling Dispose method should release memory by calling
API function private extern static Boolean CloseHandle(IntPtr handle);
- i haven't tried that yet.

Right now I am a bit confused if ReleaseComObject will release the
memory immidiately.

Oct 4 '07 #7
Thank you - You really helped me.

Regards
Piotr Kolodziej

Oct 4 '07 #8

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

Similar topics

7
3225
by: Tony Johansson | last post by:
Hello!! Assume I have a handle body pattern with classes called Handle and Body. In the Body class I store one int value for example 7 or some other integer value. In the Handle class I have...
0
2158
by: Tony Johansson | last post by:
Hello! Here I have two classes these are called Handle and Body and a main. You have the class definition below. Some basic information. In the Handle class is there a pointer to the Body. Each...
14
2712
by: Howard | last post by:
Hi, I recently had a problem where I decided to store objects in a vector. (Previously, I had always stored pointers in vectors). Well, naturally, when storing an object in a vector, using...
4
3713
by: Terry | last post by:
There are a number of things about using unmanaged resources in Windows Forms programming that is unclear to me. In C++, if you loaded an icon resource using "ExtractIcon()", the resource was...
7
1800
by: Ken Varn | last post by:
I am working in managed C++. I have a Mutex object in which I need to replace the Handle property with a new handle. The new handle is being constructed using Win32 CreateMutex call. I need to...
3
1811
by: Jarod_24 | last post by:
Dim p As Diagnostics.Process Debug.WriteLine(p.Id) Debug.WriteLine(p.Handle) What is the difference between a process's ID and Handle I see that they are different, and i know that the...
15
4011
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
2
5655
by: SM | last post by:
Hello, I've created this 'wonderful' function the embeds a youtube video in a specified div section using the Javascript DOM. Everything works OK... until I realize how bad the logical programming...
2
35494
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
4
4294
by: Donos | last post by:
Hi I have a HANDLE to an Event, like this.. HANDLE h = ::CreateEvent(NULL, FALSE, FALSE, NULL); This is running in one thread in one class. For example we will call that class as "Class A"...
0
7260
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
7537
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...
1
7099
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...
0
7525
tracyyun
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...
0
5685
agi2029
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,...
1
5086
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...
0
4746
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...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.