The introduction

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

The truth is, when I was involved in my business development and testing, there was nothing wrong with it, but when I deployed it, there was a whole bunch of symbols, and I thought, hey, I didn’t add this symbol, where did that come from? Because the project was tight at that time, the boss also knew, so I put it on hold, after the boss sent me a link, oh, I know, so I decided to write an article about fastJson, I encountered a special symbol problem, I redefine the object reference relationship.

I know the value of sharing, thanks to the little author’s sharing, otherwise I would not know what the problem is, and I am still exploring the wrong road, I think this is the value of sharing, this article as a follow-up supplement.

Reference relation determination

I like the systematic learning, studying is for example involves a concept, I will put all the systemic and the concept about the concept of out, friends that read that article, will that cause this reason is mainly because fastjson parsed into the object reference, the mentioned Java reference relationship, I think friends may not be unfamiliar with, nothing more than strong citation, weak citation, soft citation, phantom citation, then I would like to ask you to know what the citation relationship is used for? In fact, the reference relationship is mainly used to reflect the degree of unreachable state of different objects, and is used to judge the impact of the object on garbage collection.

  • Strong references: Represent strong interdependencies of dependent objects that are not normally touched by garbage collectors.
  • Weak references: Simply providing an access path to a weak-state object does not make the object exempt from garbage collection
  • Soft reference: a reference that is weaker than a strong reference
  • Fantasy reference: Objects cannot be accessed through this reference

Reference relationship analysis

We know that if you want to use object, you must do two things, one is to create objects, another is to initialize object initialized when the object, will take place the following wonderful references, is also a Java definition inaccessible level, (you don’t be fooled by professional nouns, the so-called can reach is accessible) :

  • Strongly Reachable: An object that can be accessed by one or more threads without various references. For example, if we create a new object, it is highly reachable by the thread that created it.
  • 17. Soft Reachable: a state in which an object is accessible only by soft references.
  • Weakly Reachable: Like we mentioned earlier, we can’t access through strong references or soft references, we can only access through weak references. This is the time when finalize state is very close to finalize state. When weak references are cleared, Finalize condition will be met.
  • Phantom Reachable: when there is no reference association above, and finalize has been passed, and only Phantom reference points to this object.
  • Unreachable: Indicates that an object can be purged.

But from what point of view does this reference relationship stand? It’s from the point of view of the thread, it’s from the point of view of the garbage collection, it’s completely different if you’re from the point of view of the object, which is who you refer to, you can refer to whatever objects you have, right? Let’s look at references from the point of view of the object.

  • Refer to the root object yourself
  • Self quote: circular quote, you have me, I have you
  • Reference the parent object itself
  • The parent object that references the parent object itself
  • Own path-based references

Back to my question, fastJson provides a reference detection mechanism for objects during serialization. This mechanism only detects objects as references when they are nested. If you don’t want to be detected, turn it off.