SOLVED About memory leak

U

uni00

Guest
About memory leak
I'm using two ds_grids of about 2 rows and 4 columns to build an inventory. So, just getting four items will slow down the game.
Other than ds_grid, I made only that extent that the instance will be erased if you move the character or press the enter key in front of the item. The number of instances is smaller than in the shooting game, but the computer begins to make a loud noise.
Just walking and putting items in the inventory will collect 20,000KB. What is the cause? What should I present to you? What are you guys doing? You can't erase ds_grid during the game, right?
 

TsukaYuriko

☄️
Forum Staff
Moderator
I'm using two ds_grids of about 2 rows and 4 columns to build an inventory. So, just getting four items will slow down the game.
How is it slowing down the game? What makes you think your game is slowing down?

Other than ds_grid, I made only that extent that the instance will be erased if you move the character or press the enter key in front of the item. The number of instances is smaller than in the shooting game, but the computer begins to make a loud noise.
What kind of loud noise? Might just be the CPU fans spinning... which is good, as your CPU won't be cooled otherwise. If you're running anything that uses your PC's hardware (more so than it does when it's idle), it gets hot, so the need for (more) cooling arises. Fans making noise is a natural result of this.

Just walking and putting items in the inventory will collect 20,000KB. What is the cause?
That's 20 MB, which, when weighted against a modern PC's typical 8 GB, or 8192 MB, of RAM, is basically nothing. Why does this concern you? Or am I misunderstanding something here?

You can't erase ds_grid during the game, right?
You can.

What should I present to you?
Please provide the code in question that's causing what you're describing.
 
U

uni00

Guest
How is it slowing down the game? What makes you think your game is slowing down?


What kind of loud noise? Might just be the CPU fans spinning... which is good, as your CPU won't be cooled otherwise. If you're running anything that uses your PC's hardware (more so than it does when it's idle), it gets hot, so the need for (more) cooling arises. Fans making noise is a natural result of this.


That's 20 MB, which, when weighted against a modern PC's typical 8 GB, or 8192 MB, of RAM, is basically nothing. Why does this concern you? Or am I misunderstanding something here?


You can.


Please provide the code in question that's causing what you're describing.
Thanks for everyone reply
From around 20000KB, the character movement slows down and the falling speed starts to decrease.
I want to know where it is, but...
The KB increases as you walk through the memory, 5+5+100+5+5+100, and so on.
Maybe in inventory and character movement.
CPU fan becomes very noisy from 20000KB. So something is being used too much.
FPS also went from 140 to 90.

GML:
--create(obj_menu)--
depth=-1000;

enum item{
none = 0,
draw_set = 1,
mirror = 2,
ball_w = 3,
ball_b = 4,
ueki = 5,
tubo = 6,
tue = 7,
kagi = 8,
kami = 9,
total
}

enum item_stat{
name,
description,
total
}

enum item_type{
none,
create,
wepon,
total
}

global.item_index = ds_grid_create(item.total, item_stat.total);
ds_grid_clear(global.item_index, 0);

scr_add_weapon(item.draw_set,"drawset","Tools for painting");
scr_add_weapon(item.mirror,"Wife's mirror","Show your wife herself");
scr_add_weapon(item.ball_w,"White ball","I think I can fit in something");
scr_add_weapon(item.ball_b,"Black ball","I think I can fit in something");
scr_add_weapon(item.ueki,"Wife's flowerpot","Wife liked this flower");
scr_add_weapon(item.tubo,"Aconite Vase","Acupuncture points with aconite pattern engraved. Contains a stinky liquid.");
scr_add_weapon(item.tue,"Cane","Just a cane");
scr_add_weapon(item.kagi,"Key","Key to open the door");

--draw_GUI(obj_btn)--
var iid = global.inv[# var_slot,0];
var amount = global.inv[# var_slot,1];
var name = global.item_index[# iid,item_stat.name];
var description = global.item_index[# iid, item_stat.description];

if(iid != item.none){
draw_sprite(spr_item, iid,370+(var_slot*130),670);
draw_set_color(c_white);
draw_text(375+(var_slot*130),670,string(amount));
}

--create(obj_player)--
global.inv = ds_grid_create(4,2);
ds_grid_clear(global.inv,0);

--step--
if(keyboard_check(vk_right))
{
  hspeed =1;
  sprite_index = spr_player1_walk;
  image_xscale = 1.5;
  with(o_lamp_spr){
  sprite_index=spr_lamp;
                  }
}
else if(keyboard_check(vk_left))
{
  hspeed = -1;
   sprite_index = spr_player1_walk;
   image_xscale =-1.5;
     with(o_lamp_spr){
  sprite_index=spr_lamp;
                     }
}
else {
    sprite_index = spr_player1;
    hspeed=0;
      with(o_lamp_spr){
  sprite_index=spr_lamp;
                      }
     }

if(image_xscale=1.5&&vspeed=3){
with(o_lamp_spr){
x=o_player1.x+27;
y=o_player1.y+17;
}
}
else if(image_xscale=-1.5&&vspeed=3){
with(o_lamp_spr){
x=o_player1.x-27;
y=o_player1.y+17;
}
}

--beginstep--
if(place_meeting(o_player1.x,o_player1.y+1,o_wall))
{
vspeed=0;
}
else if(!place_meeting(o_player1.x,o_player1.y+1,o_wall)&&!place_meeting(o_player1.x,o_player1.y,o_up))
{
vspeed=3;
}

--draw_GUI--
var cx = camera_get_view_x(view_camera[0]);
var cy = camera_get_view_y(view_camera[0]);

var slot = 0;
while (slot < ds_grid_width(global.inv))
{
var inst = instance_create_layer(cx+70+(31*slot), cy+200, "Instances", obj_btn);
inst.var_slot = slot;
slot ++;
}

--script1--
///@function scr_slot_modify_amount(slot,amount,override);

var slot = argument0;
var amount = argument1;
var override =argument2;

if(override == false){
global.inv[# slot,1]+=amount;
}
else{
global.inv[# slot,1] = amount; 
}

if(global.inv[# slot,1]<=0){
global.inv[# slot,0] = item.none;
global.inv[# slot,1] = 0;
}

--script2--
/// @description Adds an item and a quantity into the inventory in a valid slot.
/// @function scr_gain_item(item_ID, amount);
/// @param item_ID
/// @param amount

var iid = argument0;
var amount = argument1;
slotc = false;

var slot = 0; //A temporary variable to loop through the slots
var inventory_width = ds_grid_width(global.inv);

while (slot < inventory_width)
{
if (global.inv[# slot, 0] == iid || global.inv[# slot, 0] == item.none)
{
  global.inv[# slot, 0] = iid;
  global.inv[# slot, 1] += amount;
  return slotc = true; //Did set the slot (return/exit)
  }
slot ++;
}
return slotc = false; //Did not set slot
 
Last edited by a moderator:
Code:
--draw_GUI--
var cx = camera_get_view_x(view_camera[0]);
var cy = camera_get_view_y(view_camera[0]);

var slot = 0;
while (slot < ds_grid_width(global.inv))
{
var inst = instance_create_layer(cx+70+(31*slot), cy+200, "Instances", obj_btn);
inst.var_slot = slot;
slot ++;
}
You are continuously creating instances here. Every frame (so 60 times a second) you are creating however wide the ds_grid is worth of instances. You'll have to move the instance creation to a place in the code that only happens once, or stop using instances for the inventory system and simply use the draw functions combined with position checks for the mouse.
 
U

uni00

Guest
[QUOTE = "RefresherTowel、投稿:455007、メンバー:2533"]
[コード]
--draw_GUI--
var cx = camera_get_view_x(view_camera [0]);
var cy = camera_get_view_y(view_camera [0]);

変数スロット= 0;
while(スロット<ds_grid_width(global.inv))
{
var inst = instance_create_layer(cx + 70 +(31 * slot)、cy + 200、 "Instances"、obj_btn);
inst.var_slot = slot;
スロット++;
}
[/コード]
ここで継続的にインスタンスを作成しています。作成しているすべてのフレーム(1秒あたり60回)は、ds_gridがインスタンスに相当する幅で作成します。インスタンスの作成を1回だけ発生するコード内の場所に移動するか、インベントリシステムのインスタンスの使用を停止して、マウスの位置チェックと組み合わせた描画関数を使用するだけです。
[/見積もり]
ahhhhhhhhh!!!!! thank you so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 

TsukaYuriko

☄️
Forum Staff
Moderator
Note that the issues you were experiencing had absolutely nothing to do with memory, but with CPU usage. Memory usage, especially not a difference of 20 MB, will not slow down anything unless you are completely running out of memory (or very close to). However, using up more CPU cycles will slowly but surely decrease performance, but this will only become noticeable once you dip below your target frame rate.

For future reference, using the debug mode's profiler will tell you the cause of performance issues.
 
U

uni00

Guest
Note that the issues you were experiencing had absolutely nothing to do with memory, but with CPU usage. Memory usage, especially not a difference of 20 MB, will not slow down anything unless you are completely running out of memory (or very close to). However, using up more CPU cycles will slowly but surely decrease performance, but this will only become noticeable once you dip below your target frame rate.

For future reference, using the debug mode's profiler will tell you the cause of performance issues.
I understand! Thank you for your help
 
Top