circular-reference

Circular Reference with python lists

别说谁变了你拦得住时间么 提交于 2019-11-26 22:06:21
问题 Can someone explain this? >>> x=x[0]=[0] >>> x [[...]] >>> x is x[0] True >>> x[0][0][0][0][0][0][0] [[...]] >>> x in x True what is [...]? 回答1: That's just Python telling you that you have a circular reference; it's smart enough not to enter an infinite loop trying to print it out. 回答2: It's output by the method responsible for generating the representation of the structure. It represents a recursive structure, elided since it can be nested infinitely. 回答3: iPython will do this: [<Recursion

Circular references in Javascript / Garbage collector

怎甘沉沦 提交于 2019-11-26 18:48:29
Can somebody explain in detail how Javascript engines deal with circular references ? Is there a big difference between browsers or even node.js ? What I'm talking about is an explicit back-/next reference within objects. For instance: var objA = { prop: "foo", next: null }; var objB = { prop: "foo", prev: null }; objA.next = objB; objB.prev = objA; There we go. If we do a console.log( objA ) we can see that we created an infinite chain. The big question is, is this bad ? Does it create memory leaks when not explicitly cleaned? So do we have to objA.next = null; objB.prev = null; or will the

Json and Circular Reference Exception

强颜欢笑 提交于 2019-11-26 18:41:52
I have an object which has a circular reference to another object. Given the relationship between these objects this is the right design. To Illustrate Machine => Customer => Machine As is expected I run into an issue when I try to use Json to serialize a machine or customer object. What I am unsure of is how to resolve this issue as I don't want to break the relationship between the Machine and Customer objects. What are the options for resolving this issue? Edit Presently I am using Json method provided by the Controller base class . So the serialization I am doing is as basic as: Json

Passing an object with circular references from server to client-side Javascript while retaining circularity

余生长醉 提交于 2019-11-26 18:28:13
问题 I'm trying to pass an object with circular references from node.js server to client-side javascript. Server (node.js): var object = { circular: object } //.... app.get('/', function(req, res){ res.render('index.jade', {object: object}); }); Client-side Jade/Javascript script var object = !{JSON.stringify(object)}; Here I get the error that object contains circular references. Any way to get the object in client-side javascript, with or without circular references? 回答1: Douglas Crockford has a

Creating circular generic references

夙愿已清 提交于 2019-11-26 18:21:47
问题 I am writing an application to do some distributed calculations in a peer to peer network. In defining the network I have two class the P2PNetwork and P2PClient. I want these to be generic and so have the definitions of: P2PNetwork<T extends P2PClient<? extends P2PNetwork<T>>> P2PClient<T extends P2PNetwork<? extends T>> with P2PClient defining a method of setNetwork(T network). What I am hoping to describe with this code is: A P2PNetwork is constituted of clients of a certain type A

How to use @JsonIdentityInfo with circular references?

Deadly 提交于 2019-11-26 18:17:25
问题 I am trying to use the @JsonIdentityInfo from Jackson 2 as described here. For testing purposes I created the following two classes: public class A { private B b; // constructor(s) and getter/setter omitted } public class B { private A a; // see above } Of course, the naive approach failes: @Test public void testJacksonJr() throws Exception { A a = new A(); B b = new B(a); a.setB(b); String s = JSON.std.asString(a);// throws StackOverflowError Assert.assertEquals("{\"@id\":1,\"b\":{\"@id\":2,

Garbage collector and circular reference

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 17:35:44
Consider these two classes: public class A { B b; public A(B b) { this.b = b; } } public class B { A a; public B() { this.a = new A(this); } } If I have classes designed like above, would the objects of such classes be collected by Garbage Collector (GC)? Suppose I do this: void f() { B b = new B(); } In this method, I create an instance of B called b , and when the method returns, b goes out of scope, and the GC should be able to collect it, but if it were to collect it, it would have to collect a first which is the member of B , and to collect a , it needs to collect b first which is the

How did Microsoft create assemblies that have circular references?

冷暖自知 提交于 2019-11-26 17:04:10
In the .NET BCL there are circular references between: System.dll and System.Xml.dll System.dll and System.Configuration.dll System.Xml.dll and System.Configuration.dll Here's a screenshot from .NET Reflector that shows what I mean: How Microsoft created these assemblies is a mystery to me. Is a special compilation process required to allow this? I imagine something interesting is going on here. 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

Using print_r and var_dump with circular reference

不羁的心 提交于 2019-11-26 16:12:41
问题 I'm using the MVC framework Symfony, and it seems a lot of the built-in objects I want to debug have circular references. This makes it impossible to print the variables with print_r() or var_dump() (since they follow circular references ad infinitum or until the process runs out of memory, whichever comes first). Instead of writing my own print_r clone with some intelligence, are there better alternatives out there? I only want to be able to print a variable (object, array or scalar), either

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

对着背影说爱祢 提交于 2019-11-26 12:53:55
I have the following code in one of my controllers: @Controller @RequestMapping("/preference") public class PreferenceController { @RequestMapping(method = RequestMethod.GET, produces = "text/html") public String preference() { return "preference"; } } I am simply trying to test it using Spring MVC test as follows: @ContextConfiguration @WebAppConfiguration @RunWith(SpringJUnit4ClassRunner.class) public class PreferenceControllerTest { @Autowired private WebApplicationContext ctx; private MockMvc mockMvc; @Before public void setup() { mockMvc = webAppContextSetup(ctx).build(); } @Test public