After many months of programming with ArcObjects, I still feel somewhat unsure about two related issues:
For some operations, workspaces and datasets must be explicitly opened before they can be used. (For example, workspaces are opened via IWorkspaceFactory.Open(), ITables via IWorkspace.OpenTable(), etc.) On the other hand, there are operations that can be performed without having to open workspaces or datasets first (e.g. geoprocessing, or operations that accept INames as inputs).
Thus I suspect that there is a certain cost involved with opening a workspace or dataset, which can only be avoided for the latter type of operations. And because of that, I tend to keep (cache) references to the opened IWorkspace, ITable, IFeatureClass, … instances whenever I open these for the first time.
My first uncertainty is whether caching IWorkspace, ITable, etc. references could ever get me into trouble. More specifically, are there any ArcGIS operations, e.g. on tables, that require that there be no live references to "open" tables?
(I'm aware of only one potential problem source at the moment: If a workspace or dataset gets deleted, all cached references to it should be thrown away.)
My second, related uncertainty concerns how long I should cache workspace and dataset references (at most). Let's say I'm writing an ArcGIS extension; would it be OK to open required workspaces when the extension is loaded, and only reset the references when it is unloaded? Would it even be OK if I did the same for datasets?
Links to ESRI reference documentation (or insider knowledge) is most welcome.