What lifetimes do I use to create Rust structs that reference each other cyclically?

It is not possible to create cyclic structures with borrowed pointers. There is not any good way of achieving cyclic data structures at present; the only real solutions are: Use reference counting with Rc<T> with a cyclic structure with Rc::new() and Rc:downgrade(). Read the rc module documentation and be careful to not create cyclic structures … Read more

Converting circular structure to JSON — Any way to find what field it is complaining about?

Pardon me if this is too obvious. At the time of writing, I dont know what you have tried. insert console.log(the object); replacing ‘the object’ with the object you are passing to JSON.stringify() insert this line before the JSON.stringify call and look in the console log (shift control J) for the object. In the console … Read more

Json and Circular Reference Exception

Update: Do not try to use NonSerializedAttribute, as the JavaScriptSerializer apparently ignores it. Instead, use the ScriptIgnoreAttribute in System.Web.Script.Serialization. public class Machine { public string Customer { get; set; } // Other members // … } public class Customer { [ScriptIgnore] public Machine Machine { get; set; } // Parent reference? // Other members // … Read more

Circular references in Javascript / Garbage collector

Any half-decent garbage collector will handle cycles. Cycles are only a problem if you do naive reference counting. Most garbage collectors don’t do ref-counting (both because it can’t handle cycles, and because it’s inefficient). Instead, they simply follow every reference they can find, starting from “roots” (typically globals and stack-based variables), and mark everything they … Read more

How to serialize DOM node to JSON even if there are circular references?

http://jsonml.org/ takes a shot at a grammar for converting XHTML DOM elements into JSON. An an example: <ul> <li style=”color:red”>First Item</li> <li title=”Some hover text.” style=”color:green”>Second Item</li> <li><span class=”code-example-third”>Third</span> Item</li> </ul> becomes [“ul”, [“li”, {“style”: “color:red”}, “First Item”], [“li”, {“title”: “Some hover text.”, “style”: “color:green”}, “Second Item”], [“li”, [“span”, {“class”: “code-example-third”}, “Third”], ” Item” ] … Read more

How and when to appropriately use weakref in Python

Yep, weakref’s excellent here. Specifically, instead of: self.children = {} use: self.children = weakref.WeakValueDictionary() Nothing else needs change in your code. This way, when a child has no other differences, it just goes away — and so does the entry in the parent’s children map that has that child as the value. Avoiding reference loops … Read more

How to create a circularly referenced type in TypeScript?

The creator of TypeScript explains how to create recursive types here. The workaround for the circular reference is to use extends Array. In your case this would lead to this solution: type Document = number | string | DocumentArray; interface DocumentArray extends Array<Document> { } Update (TypeScript 3.7) Starting with TypeScript 3.7, recursive type aliases … Read more

How did Microsoft create assemblies that have circular references?

I can only tell how the Mono Project does this. The theorem is quite simple, though it gives a code mess. They first compile System.Configuration.dll, without the part needing the reference to System.Xml.dll. After this, they compile System.Xml.dll the normal way. Now comes the magic. They recompile System.configuration.dll, with the part needing the reference to … Read more

tech