Solved! Go to Solution.
Is there any way for me to detect whether the object has already been release?
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]
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.
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.
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.
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 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?