Every service gets a local “copy” of the pipeline. I say “copy”, because it is not really a copy, depending upon the type of data in the pipeline. Here’s how it works:
String variables that are not contained within a document are passed by value (you get a copy).
Documents (which are really object instances of the IData class) and other objects are passed by Reference (you get a reference “handle”).
Calling pub.flow:clearPipeline in a child service removes the strings in the local pipeline, but since they are copies, does not remove them from the parent pipeline. Documents and objects simply get dereferenced when clearPipeline is called (i.e. the ref count on the object is reduced by 1 - in general, an object will stay “alive” while it’s ref count is greater than 0 - indicating that some other object still has a handle on it and is probably using it).
There are other implications of this as well, that you need to understand:
- If you modify the value of a string variable in a child service into which it is passed, and then drop that variable in the child service, it will have absolutely no impact on the value of that variable in the parent service. (If you do not drop it, then the value in the parent will get overwritten when the child pipeline is merged with the parent pipeline upon completion of the child service).
- If you modify the value of a string variable contained within a document in a child service into which that document is passed, and then drop that variable in the child service, it WILL have already updated the value in the parent service since documents are objects and there is only a single “copy”.
Hope that explains it in a bit more detail…