Scene change without memory cost

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By HardFire1

Hello, please help. When I turn between scenes, I have them change. But if I do it several times, then RAM memory gets clogged up with me. Can I somehow release her? Please give examples.

ScreenShot

I don’t entirely know what your asking, let alone what the problem is. But I would recommend in not putting change_scene() in the _physics_process() function, as that function could be executed many times in a second.

Also, the next time you ask a question, please paste your code instead of taking a screenshot.

Ertain | 2019-04-21 23:23

Sorry for my English. I’m trying to say that when the game is changing quickly the same scenes (the player goes into the test location), then the RAM consumption starts to grow. And after the character has stopped the memory does not decline. Just enough is only 20 transitions to increase memory consumption by at least 2 mb and I think that for such a small game like mine this is very critical. Here is the code.

*MAP JUMPER*
 extends Area2D

 export(String, FILE, "*.tscn") var world_scene



 func _on_Map_jump_body_entered(body):
     if body.name == "Player":
	
	var Global = get_node("/root/Global")
	
	if Global.Game["Player"]["Entered"] == 0:
		Global.Game["Player"]["Entered"] = 1
	else:
		Global.Game["Player"]["Entered"] = 0
		
	var root = get_tree().get_root()
	var id = root.get_child_count()-1
	root.get_child(id).queue_free()
	
	get_tree().change_scene(world_scene)

Quick Transition Memory Usage Chart

With approximately 10 transitions, memory consumption increased by 2 mb

HardFire1 | 2019-04-22 01:34

What do you exactly mean by “transitions”? Shouldn’t your character move to the test area once, and the previous scene freed from memory? As for an increase of 2MBs of RAM, well, that could be due to the overhead that you may receive from an interpreted (i.e. scripting) language.

Ertain | 2019-04-22 07:37

:bust_in_silhouette: Reply From: HardFire1

Resolved, the problem was caused by such a bunch

onready var Tree_Node = get_node("Tree")
onready var Tree_controller = 
load("res://Maps/Global/script/Tree/Tree_controller.tscn").instance() 


onready var House_Node = get_node("House")
onready var House_controller = 
load("res://Maps/Global/script/House/House_contorller.tscn").instance() 

onready var Citizen_Node = get_node("Citizen")
onready var Citizen_controller = 
load("res://Mobs/Citizen/Citizen_Controler.tscn").instance() 

onready var camera = get_node("Player/Camera2D")
onready var Camera_controller = 
load("res://Maps/Global/script/Camera/Camera.tscn").instance() 

How I decided this:

func _exit_tree():
 Tree_controller.queue_free()
 House_controller.queue_free()
 Citizen_controller.queue_free()
 Camera_controller.queue_free()

As I see it … When the scene changes with the function “change_scene ()” it for some reason does not break the connection with the scenes it causes. As a consequence, the objects remain, and with a quick change of locations, these objects are piled up thereby loading the memory.