Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: prevent circular references #124

Open
djjd47130 opened this issue Feb 1, 2018 · 0 comments
Open

Request: prevent circular references #124

djjd47130 opened this issue Feb 1, 2018 · 0 comments
Assignees

Comments

@djjd47130
Copy link

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...

O1:= SO;
O2:= SO;
O1.O['foo']:= O2;
O2.O['bar']:= O1;

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".

@onryldz onryldz self-assigned this Feb 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants