You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was facing an Out of Memory error while serializing a JSON object. Finally after almost an hour of digging, stepping through the X-SuperObject library, I finally figured out what was causing it: A circular reference as a result of my code accidentally assigning the wrong thing.
How it happened:
I have a number of nested objects/arrays which I was serializing. At one point, I was accidentally assigning an object which was already assigned on a parent level. For example...
In the end, when I was calling AsJson(), there was a loop in TJSONObject.AsJSONString, which in turn triggered a few more things, leading back to that same loop.
Proposal:
When assigning objects or arrays, provide an option to check for circular references. This should be as simple as stepping up through the parent hierarchy and checking if any of the elements matches the pointer of the one being assigned, or any of its children. If so, raise an exception such as "Circular reference detected".
The text was updated successfully, but these errors were encountered:
I was facing an Out of Memory error while serializing a JSON object. Finally after almost an hour of digging, stepping through the X-SuperObject library, I finally figured out what was causing it: A circular reference as a result of my code accidentally assigning the wrong thing.
How it happened:
I have a number of nested objects/arrays which I was serializing. At one point, I was accidentally assigning an object which was already assigned on a parent level. For example...
In the end, when I was calling
AsJson()
, there was a loop inTJSONObject.AsJSONString
, which in turn triggered a few more things, leading back to that same loop.Proposal:
When assigning objects or arrays, provide an option to check for circular references. This should be as simple as stepping up through the parent hierarchy and checking if any of the elements matches the pointer of the one being assigned, or any of its children. If so, raise an exception such as "Circular reference detected".
The text was updated successfully, but these errors were encountered: