views:

140

answers:

1

On timer tick I am allocating new ClearCase ApplicationClass object, Is following code okay? Or Do I need to release memory, If yes, How? I am using ClearCase Interop of ccauto.dll, I believe ccauto.dll is unmanaged code, I am confused, am I supposed to release the memory or not?

Please advise.

    private void timer1_Tick(object sender, EventArgs e)
    {
        try
        {
            IClearCase ccNew = new ApplicationClass();
            CCVOB vob = ccNew.get_VOB(ClearCaseVOB);
            ccNew = null;
        }
        catch
        {
        }
    }
A: 

2 comments:

  • according to "About CAL3" article

Once you "GET" a ClearCase.Application object programmatically, do you need to keep getting the object in CAL?
Once the ClearCase.Application object is obtained, it can be used to get other objects without having to create them again. CAL ensures as best it can that CAL objects stay synchronized with the underlying ClearCase data, refreshing as necessary when invoking properties and methods. However, the CAL objects can become invalid if someone deletes the underlying ClearCase data while a reference is still held by the CAL object.

Meaning: you could set a CCVOB instace once and for all (unless you think the Vob will disappear... which should be a very rare event!)

  • In C#, placing code in a using block ensures that the objects are disposed (though not necessarily collected) as soon as control leaves the block.

I am not sure if CCVOB implements Disposable, but if it does, setting it to null explicitly would prevent it to be properly disposed.
So I would not recommend ccNew = null;

VonC