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

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

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

How to avoid the “Circular view path” exception with Spring MVC test

@Controller → @RestController I had the same issue and I noticed that my controller was also annotated with @Controller. Replacing it with @RestController solved the issue. Here is the explanation from Spring Web MVC: @RestController is a composed annotation that is itself meta-annotated with @Controller and @ResponseBody indicating a controller whose every method inherits the … Read more