Resolving cyclic references during Deep mask

I have tried to resolve the cyclic dependencies during Deep masking by storing the already masked objects in a map and checking them to see if an object has to be masked. If an object has already been masked, an empty string is returned(not sure if returning empty string is correct).