NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

ca_discardobjhandle versus TS_EngineReleaseSeqFileEx

Hi All,

 

I am confused with using ca_discardobjhandle and TS_EngineReleaseSeqFileEx in my cvi code. I have a dll which will be called in process model before the main sequence callback. In that dll I will get the reference of client sequence file.

1) If I discard that reference or release that file, will the teststand completely remove that sequence file from its memory..? If so then how teststand can execute that sequence file ..?

2) If I don't discard that reference, will it cause the memory leaks..?

 

3) I read somewhere that after getting the reference to any objects it should be released or discard after its use(at the end). But by doing this so will it affect the further execution if the same object is again called..?  

4) I got the engine object by using sequence context. Should I discard the engine object at the end of the code..? If so then how the teststand will get the engine reference..?

 

Thanks.

0 Kudos
Message 1 of 4
(3,213 Views)

1) The file will be removed from memory when all references to it are released, not just the ones you have. If the execution has a reference to the file it will stay in memory for that reason.

2) It depends, how did you get the reference? References passed in as a parameter to a code module function are owned by the caller, and not intended to be released by the called function. If you do so you will potentially cause crashes and memory corruption. References gotten as return values or output values from functions your code calls are owned by your code and need to be released when you are done with them.

3) I do not understand this question. Really just think about objects as having a count associated with them. Whenever you get a new object by making a function call, it will have its count incremented before it's returned to you and decremented when you discard it. When the count goes to 0 the object will be removed/deleted from memory. Keep in mind that references passed into your function are owned by the caller though, and you should thus NOT discard them.

4) Yes. see 3)

 

Also you mentioned both ca_discardobjhandle and TS_EngineReleaseSeqFileEx. Make sure you understand how to use these and what the difference is. TS_EngineReleaseSeqFileEx is only to be used when you get the sequence file by calling certain APIs. The help for those APIs will say whether or not you need to call TS_EngineReleaseSeqFileEx. Even if you do need to call TS_EngineReleaseSeqFileEx, you still also need to call ca_discardobjhandle afterwards, they are for different purposes. The later is for the reference count for the lifetime of the object, and the former is for the sequence file cache reference for whether subsequent calls to APIs to get sequence files should return the same object or not.

 

Hope this helps clarify things.

-Doug

Message 2 of 4
(3,204 Views)

Doug,

 

Thanks for your reply.

 

I have the sequence object reference and a step obj ref(this step resides under the sequence). By discarding the seq ref will also discard the step obj refernce ?

 

Memory leaks:

 

The memory allocated to a char pointer by a TestStand API cannot be freed completely using CA_freememory. Though it tries to free the memory, still I could see some garbage value pointed by that pointer. Is that a bug with teststand API..?? Or How can I free the memory completely..??

0 Kudos
Message 3 of 4
(3,198 Views)

1) Every reference you own (i.e. returned to you by an API call) you are responsible for releasing (i.e. calling CA_DiscardObjHandle on). Some programming languages handle this for you automatically or with smart pointer classes, but for CVI code you need to call CA_DiscardObjHandle.

 

2) Freeing memory doesn't mean it is immediately cleared or invalidated in anyway. What happens to the memory depends on the heap allocation algorithm and typically it is just put into some sort of list of free memory which can be reused at some point in the future. Just because you see recognizable data at a particular memory location does NOT mean that that memory hasn't been deallocated.

 

-Doug

0 Kudos
Message 4 of 4
(3,193 Views)