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

Why aren't these objects being kept alive

Hi there,

This is actually (probably) a C# or .NET issue. I'm working on an VS 2005
AddIn and at one point I'm caching all "EnvDTE80.ErrorItem" objects that
result from compiling one or more projects in an arbitrary solution (which
my own code carries out). These objects simply store each warning, error or
other message as seen in the "Error List" window in VS (when you build a
solution). Later on, when I attempt to look at the properties of some (but
not all) of these objects while debuugging, each property is throwing a
"System.Runtime.InteropServices.COMException". It doesn't happen at first
(right after compiling various projects) but only later on after all
compiling is complete. It appears to me (though I'm not certain) that the
properties are being generated on-the-fly and whatever underlying objects
they rely on to retrieve this info are dead by the time I need them. My
question is why? Shouldn't these objects be kept alive as long as my own
collection of "ErrorItem" objects remain alive? Isn't this how things work
in .NET? Thanks in advance..
Sep 7 '07 #1
2 1242

That's how .NET works to keep .NET managed objects alive, yes.
However, in this case you're dealing with .NET wrappers of native
objects. Your references keep the .NET wrappers alive (and that's why
you don't get a null reference exception), but apparently the
underlying native objects are being destroyed (not necessarily because
they are out of scope, but more likely 'cause the routine that created
them no longer needs them and thus specifically destroys them).

I hope this helps explain the paradox you're seeing, but unfortunately
I don't have a solution to the underlying problem of needing that data
later on (unless you can cache it while it's available yourself--the
real data, not the references).

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Fri, 7 Sep 2007 11:08:41 -0400, "MikeP" <no_spam@_nospam.com>
wrote:
>Hi there,

This is actually (probably) a C# or .NET issue. I'm working on an VS 2005
AddIn and at one point I'm caching all "EnvDTE80.ErrorItem" objects that
result from compiling one or more projects in an arbitrary solution (which
my own code carries out). These objects simply store each warning, error or
other message as seen in the "Error List" window in VS (when you build a
solution). Later on, when I attempt to look at the properties of some (but
not all) of these objects while debuugging, each property is throwing a
"System.Runtime.InteropServices.COMException". It doesn't happen at first
(right after compiling various projects) but only later on after all
compiling is complete. It appears to me (though I'm not certain) that the
properties are being generated on-the-fly and whatever underlying objects
they rely on to retrieve this info are dead by the time I need them. My
question is why? Shouldn't these objects be kept alive as long as my own
collection of "ErrorItem" objects remain alive? Isn't this how things work
in .NET? Thanks in advance..
Sep 7 '07 #2
That's how .NET works to keep .NET managed objects alive, yes.
However, in this case you're dealing with .NET wrappers of native
objects. Your references keep the .NET wrappers alive (and that's why
you don't get a null reference exception), but apparently the
underlying native objects are being destroyed (not necessarily because
they are out of scope, but more likely 'cause the routine that created
them no longer needs them and thus specifically destroys them).

I hope this helps explain the paradox you're seeing, but unfortunately
I don't have a solution to the underlying problem of needing that data
later on (unless you can cache it while it's available yourself--the
real data, not the references).
Thanks for the reply. I still don't see why they're being prematurely killed
off however. The .NET wrappers should keep them alive since I'm keeping them
alive. Any underlying COM objects for instance should be maintained so long
as their reference count doesn't drop to zero. The .NET object itself
shouldn't allow that until I release it (or so the theory goes).
Sep 8 '07 #3

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

Similar topics

6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
0
by: elcinturapartida | last post by:
Hello all, I am not sure if this question is about threading or serial i/o - it has elements of both. I'm on WinXP (desktop) and WinNT (labtop), when I run miniterm.py there is no problem both...
15
by: Chris Capel | last post by:
I've heard a lot of talk on the forum about memory managment in .NET and disposing things, finalizing them, garbage collection, etc. My question is which managed types need to be disposed after...
1
by: emma middlebrook | last post by:
Hi I want to find out what objects are due to receive an event i.e. those that have added themselves as an event handler via +=. Yes, it's a little pointless perhaps (or can anyone give some...
3
by: owatona | last post by:
Hi to all, I would like to know how .net manage the objects and what are the cicle of life of the objects... Are the same this cicle, for the objects created in windows applications and for the...
3
by: N8 | last post by:
I am trying to get an exception to occur and consequently found that when adding a target method to a delegates invocation list, a copy of that object is added instead of a reference to the object....
5
by: pitdog | last post by:
Hello, I am unable to find information on about this issue so I thought I would post and ask. I have a class that is using the sigleton pattern as it has an internal static instance of...
25
by: Michal Kwiatkowski | last post by:
Hi, Code below shows that property() works only if you use it within a class. ------------------------------------------------ class A(object): pass a = A() a.y = 7
1
by: t.mitchell | last post by:
Hi, I have a python gtk app that allows users to have one project open at a time. I have recently discovered that projects are not being freed when they are closed - the refcount is not hitting...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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
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
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,...

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.