warning

“Warning! Warning! Warning!” A shrill warning is heard in the JavaScript implementation hall.

“Report: memory is about to overflow, please clean up the invalid memory in time to release resources!” A warning was displayed on a large screen in the middle of the hall, accompanied by a flurry of alarm bells.

“What’s the matter? This page has only been open for a moment, memory consumption is so big? I’ve been there several times!” The head of the JavaScript main thread, which is the JavaScript execution hall, said, “I’ll have to go to the variables hall again!”

With that, the JavaScript main thread drops what it’s doing and heads down the hall of variables.

Variable hall

“Crowded, you move over!” The JavaScript boss, who hadn’t even reached the variable hall, heard the swearing in the distance.

“No, that side is already full of variables!”

“Squeeze, squeeze, my half foot is still outside!”

“What! You’re saying it again! It’s too loud to hear!”

The JavaScript boss saw that things were about to get worse, and if it wasn’t cleaned up in time, these variables would go backwards, causing the JavaScript main thread to run subconsciously.

After a while, the JavaScript main thread finally made it to the hall of Variables, ran to the stands in front of the hall, and took a look around.

The whole hall is divided into three areas, two 16MB areas (new area), the area marked with “FROM” is crowded with variables, the area marked with “TO” is empty, and a large area (1.4g old area) is also nearly filled.

‘Now, don’t make any noise! JavaScript boss yells: “I’m here to reclaim memory!”

“Hurry up, hurry up, I’ve got variables coming in behind me.” “Said variable, whose half-foot was just outside the hall.

Call the roll

“Global object, get out of here!” “Shouted the JavaScript boss.

“Here, here! Old living area in spread eager voice: “you can calculate come, I all quick be crowded dead, this time can want me in old living area also give clean up clean up!”

“You’re the fattest one and you take up the most space!” The other variables in the old block mutter.

“I’m the boss! None of you would be alive here without me!”

“Yes! Come on! Hurriedly come up to see, here already quick was crowded burst, the memory of your old living area is quick also crowded!”

“Yes! Leave it to me!” With that, the global took a bag of Pointers out of his pocket and said, “Next, I’ll call the roll and continue to call the variable references you saved! Start now!”

“Object OA!” “Shouted the global object.

“Here it is! Excited shout from old living area in spread: “that I also began! You wait for me to finish ha.”

“Then you begin! “Said the global object.

“Variable VA!

“To! I’m a base type, no references to other variables! OA go on!”

“Well! Function FA!” The global object continues.

“To! So now I start quoting the reference to the variable I saved! Object OA you wait!”

“Well! You start!”

“…”

After a while, the global object finally started the second registration.

“…”

After a while, the global object finally finished naming.

“Okay, now we all know if we’ve been called. I’ll take it from here. You go home.” The JavaScript boss said to the global object.

What kind of garbage are you?

“JavaScript boss walked to the freshmen area, crowded with freshmen variables, looking at a strange face, JavaScript boss walked to the first variable.

“Speak! What kind of garbage are you?”

“The garbage? I’m not garbage!”

“You were called?”

“No.”

“Then you’re rubbish! Stay here.” The JavaScript boss moves to the next variable.

“How about you? What rubbish is it?”

“I should be recyclable!” “Said the variable with a grimace.

“I see you know your fate. Stay here!” JavaScript boss continues to move forward.

“What about you?”

“I’m not garbage, I’m called!”

“How proud you are! Go TO the other side!” The JavaScript boss pointed TO another new section, TO.

“Ok!” say, variable scamper scamper of ran past.

JavaScript boss continues to walk backwards…

“Finally finished, ok, now still in this FROM variable behave yourself, disappear!”

Whew, the Cenozoic area pointed to by FROM was suddenly emptied, and the whole hall of variables was suddenly empty.

Looking at the empty FROM, the JavaScript boss picks up the FROM flag placed in front of the empty space, switches it with the TO flag, and nods in satisfaction.

The old generation

“Eldest brother eldest brother, old living generation here also clear bai!” Global variable yells.

“Coming!

All of a sudden, the JavaScript boss goes to the first place in the old section and takes a look at global variables.

“You know! I’m not garbage, I if garbage, that sitting can be garbage!” The global variable said unhurriedly.

“Only you strong, you are not my generation!”

“But I was your first one!” The global variable says proudly.

“How proud you are! All right, I’m on to the next one.” The JavaScript boss moves on to the next variable.

“What about you?” “Asked the JavaScript boss.

“I am an Object, directly belonging to the global Object.”

“Oh, one by one, proud.”

. Finally, all the global objects are confirmed.

“What kind of garbage are you? JavaScript boss knows soy sauce time is over, refreshing.

“I’ve been counted twice!” The variable raised his head proudly.

“Look at you.”

“What about you?” The JavaScript boss asks for the next variable.

“I’m garbage.” The variable bowed his head in grievance.

“Disappear or should I help you?”

“I’ll disappear without your help.” As he spoke, the variable’s position suddenly became empty.

“Hey! It takes up a lot of space!”

.

As the JavaScript boss goes down, the space where the variables are is empty.

“You this old area space still enough, I don’t carry on fragmentary collation ha, wait for next time I in collation, MY side still busy.” The JavaScript boss said as he walked out of the hall of variables.

“Good le! You go slow, “said the global variable.

Visit again

After a while, the JavaScript boss in the execution lobby stops working, looks at the monitor panel in the lobby, reaches the threshold again, and heads back to the variables lobby without warning.

“Hey! Boss, there you go again. “The global object saw JavaScript boss walking to the grandstand and rushed to meet him.

“Ok, you are here, sign up ~”

“W ~”

It was a lot shorter than the last time.

“Okay, you go home. I’ll take care of it.” The JavaScript boss walks to FROM.

“See you last time also in this ah, this time was the point to the name?” The JavaScript boss asked about the first variable.

“That must be, this time also!”

“OK that you go old living area seeks a suitable position to stay.”

‘Yes! Just promoted to old – living area of variable a face satisfied to that spacious old – living area walked.

“Haven’t seen you last time, say, what rubbish are you?”

“I…”

“Ok, I know, you stay here!”

. A similar process was repeated, but in a follow-up interview the JavaScript boss noticed a problem: the TO space was already 25% used.

“You can’t insert variables into TO, otherwise there will be no room for new variables!” Thought the JavaScript boss.

“Are you garbage?” The JavaScript boss says to the next variable.

“I’m not garbage, I’m called!”

“Emmm… That you go old living generation of space go!” JavaScript boss thought for a moment and said.

“Really?” The variable’s eyes lit up.

“All right, go ahead and obey!”

. After that, all new variables that are named are placed in the old section by the JavaScript boss.

defragmentation

After passing through the new class variables, the JavaScript boss moves to the old class, and the same process happens again.

“Boss, boss, clean up the space!” Global variables remember what the JavaScript boss said earlier.

“Then I’ll tidy it up for you this time! Because before the variable was clear after a lot of, you do not sit together, hurriedly look at the front empty seat to sit forward!”

“Hurrah! The variables of old living area people began the movement of bustling and bustling, soon, sit neatly.

“Good, finishing also finishing, that I go ha ~”

“All right, take your time.”

die

With the small triangular arrow on the screen pointing to the page, the JavaScript main thread put down their work, and the bustling hall of variables became quiet for a moment. Everyone’s faces were solemn, and soon it was gone.

A gust of wind blew and raised specks of dust.

reading

  • Browser clutter