DynamoDS/Dynamo — pull request #2419 by ke-yu (2014-09-16 02:53:47+00:00)
Title: Change GCRetain() and GCRelease() order in BuildInFunctionEndPoint

This pull request is to fix defect [MAGN-4605 Multi-output custom nodes do not always accurately output contents](http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-4605#).

When the VM returns from a builtin function, it will decrease the reference count for input parameters and then increase the reference count for return value. But, if the memory that the return value points to is part of the memory that the input parameter points to, this piece of memory may be garbage collected before it is returned.

An example is the input parameter is a dictionary. Because of array copy semantics, a temporary dictionary will be created and get garbage collected when the function is returned, and if return value is some value in the dictionary, garbage information will be returned as the whole dictionary is disposed.

A quick fix is to change the order of increase/decrease reference count.

I'm thinking about introducing memory verification logic for some operations to catch this kind of memory corruption at the early stage. Will do that in the other pull request.

@junmendoza , @lukechurch, @sharadkjaiswal please take a look.