The exception is not caused by calling a method of that released COM object, but caused by releasing it again with my generic releasing method... it use "if (obj is IEnumerable)" to check the interface it supports. Because it is already released, the checking will fail in the second call of the releasing method.Now I decide to resolve this issue by coding carefully, not to release the same COM object twice, even though the logic will be a bit more comoplicated.
For some reason, your statement is leading me to believe that you are releasing an object, then trying to do a method call on that object, but first checking whether the object you released is null, otherwise calling that method on a released object without first re-assigning that released object the value of null is giving you the exception. What do you expect? If you were in Java, assigning an object reference to null would still give you an exception when you tried calling a method on that object.I still don't understand why you are trying to call a method on an object after you've released it. Can anyone explain that to me? I would really like to understand why you are trying to do this.
If you are releasing fList and f at the end of your procedure/function/method - whatever, how are you getting an exception?Also, telling us what kind of exception you're getting would help. Is it NullPointerException? AutomationException? something else?
Not to nitpick, but if you set a reference to null *after* you have explicitly released it, what other value to expect it to have when you test it for null?Is Sui trying to call a method on that Object just before it is actually killed off? Not a good idea.
If you set your variable to null after calling the release you should be able to test to see if the variable is null and avoid calling it a second time.
Just because I am releasing it intentionally, I need to care. Because the current way I am structuring the code doesn't support double releasing. Releasing a released COM object will throw exception.
Using releaseComObject is necessary in .NET code because some objects' reference count don't decrement when they go out of scope and don't get collected in GarbageCollection. This is a problem for cursor because you can exceed the number of open cursors you are allowed to have. It is also a problem with featureclasses and workspaces and other geodatabase objects that maintain locks until they are explicitly release.If you set your variable to null after calling the release you should be able to test to see if the variable is null and avoid calling it a second time. Aside from that I would only suggest keeping a tighter control on the variables to avoid release being called a an object separated from the RCW.
Personally, I don't think you should care whether it has been released or not after the fact, because you would be the person who is releasing it intentionally or via the the way you are structuring your code.[/url]
Is there any way for me to detect whether the object has already been release?
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.