Memory leak? Help to dispose graphic

Hello everyone,

Need some help to know what to do here. The situation is I'm using ProgressBar by efeberk.
When the bar is finished displaying I get a message in the console, which to me means the bitmap is not disposed.
I tried to add in a dispose section but I obviously do not have the skill. Nothing I tried worked.
Calling all coders!
skipcut.png leakcut.png

After the cutscene is skipped, the message keeps coming up when going into the menu.

Here is the script with my additions I modified from another script.
Spoiler: progressbar
Code:
=begin
===============================================================================
 ProgressBar by efeberk
 Version: RGSS3
===============================================================================
 This script will allow player waits while progress bar fills up.

--------------------------------------------------------------------------------

Call:

progressbar(x, y, text, frames)

x : window x coordinate
y : window y coordinate
text = Message
frames = how long time costs to fill up progressbar

=end
#==============================================================================

module EFE

  BAR_COLOR1 = Color.new(27, 174, 42, 255)
  BAR_COLOR2 = Color.new(206, 166, 36, 255)

end

#==============================================================================

class Window_ProgressBar < Window_Base

  def initialize(x, y, text, frames)
    @frame = 0
    @frame2 = frames
    super(x, y, 250, 90)
    refresh(text)
  end

  def line_color
    color = normal_color
    color.alpha = 48
    color
  end

  def draw_horz_line(y)
    line_y = y + line_height / 2 - 1
    contents.fill_rect(0, line_y, contents_width, 2, line_color)
  end

  def refresh(text)
    contents.clear
    draw_horz_line(20)
    draw_text(0, 0, contents.width, 32, text, 1)
    @frame += 1.0 / @frame2.to_f
    draw_gauge(0, 32, contents.width, @frame, EFE::BAR_COLOR1, EFE::BAR_COLOR2)
  end

end

#==============================================================================

class Scene_ProgressBar < Scene_Base

  def start
    super
    create_window
    create_background
  end

  def prepare(x, y, text, frames)
    @window_x = x
    @window_y = y
    @text = text
    @frames = frames
  end

  def update
    super
    @frames -= 1
    @progressbar.refresh(@text)
    SceneManager.return if @frames == 1
  end

  def create_window
    @progressbar = Window_ProgressBar.new(@window_x, @window_y, @text, @frames)
  end

  def create_background
    @background_sprite = Sprite.new
    @background_sprite.bitmap = SceneManager.background_bitmap
  end

end

#==============================================================================
# ■ Scene Progressbar
#==============================================================================
class Scene_Progressbar

  #--------------------------------------------------------------------------
  # ● Dispose
  #--------------------------------------------------------------------------        
  def dispose
      Graphics.freeze
      dispose_background
      dispose_progressbar

  end
   
  #--------------------------------------------------------------------------
  # ● Dispose Background
  #--------------------------------------------------------------------------          
  def dispose_background
      @background_sprite.dispose
      @background.dispose    
  end

  #--------------------------------------------------------------------------
  # ● Dispose Layout
  #--------------------------------------------------------------------------            
  def dispose_progressbar
      @Window_ProgressBar.bitmap.dispose
      @Window_ProgressBar.dispose
      @progressbar.bitmap.dispose
      @progressbar.dispose
  end
   
end

#---------------------------------------------------------------------------

class Game_Interpreter
  def progressbar(x, y, text, frames)
    SceneManager.call(Scene_ProgressBar)
    SceneManager.scene.prepare(x, y, text, frames)
    Fiber.yield while SceneManager.scene_is?(Scene_ProgressBar)
  end
end

This is where I have left off. I don't know what else to try. And another question, is this even a problem? Without my meddling that is.
Get rid of the second part of Scene_ProgressBar, that is not needed at all (and it won't even run that way).

Just add this method into Scene_ProgressBar:
Code:
  def dispose_all_windows
    super
    @background_sprite.bitmap.dispose
    @background_sprite.dispose
  end
The background image is not disposed properly, that is what you see on the console (you can see that it refers to a Sprite object, and only one of those is created in that scene).

And yes, it is a problem. Every single memory leak is a problem.
You can see only one, because you executed that script call only once. Do it more times, you will see one new leak after every single use of that script call.
That should tell how serious it can be. On top of that, some undisposed sprites can cause random crashes too. This one in particular can't, but others may.
Thank you @Sixth
I guess I missed the super part. What I had shown was how far I went to try and identify what need to go in. Since It did not work for me I was stumped to see what else to add, but you have shown me that it was the background sprite. And a bit off on identifying the code.
So thanks again. I got that far because of when I was looking for the answer to the Rin title screen you helped me with.
Now I know more.

I was also getting lots of messages when going into battle, and I found it to be caused by Graphical Object Global Reference by Mithran.
More play testing will tell if there are any more leaks.
Those console logs are not "caused" by Mithran's script.
The sole purpose of that script is to alert you about these errors caused by other scripts. A pretty handy tool for any scripter, I use it too just to make sure I don't forget to dispose anything.

The default battle transition will show messages like "<Sprite: 0x000000> is already disposed!" or something similar.
That is an example of poor sprite control right there, but aside from that, mistakes like these won't do much harm, so if you see only these reported, you can safely ignore them. Fixing it wouldn't take long, but since I don't really use the default battle system, I never even tried to get rid of these faulty dispose calls there.
If you see other reports about memory leaks and/or potential crash issues, than you have real problems.
Well in that case I have one more @Sixth
MOG Transition EX. Shows up when entering a battle.
Mog transition.png
I did a test and this is where the problem is.
Spoiler: MOG Transition EX
Code:
#==============================================================================
# +++ MOG - Transition EX (V1.4) +++
#==============================================================================
# By Moghunter
# https://atelierrgss.wordpress.com/
#==============================================================================
# - Adds effects to battle transitions.
#==============================================================================
# To set the transition effect use the code below.
#
# transition_ex(X)
#
# X - (Effect)
#
# 0 - Zoom IN
# 1 - Zoom OUT - OK
# 2 - Angle
# 3 - Wave
# 4 - Shake - Bad
# 5 - Screen Slice
# 6 - Random
# 7 - Nothing (Default Rpg Maker Transition)
#
#==============================================================================
# - DEFAULT TRANSITION NAME
#==============================================================================
# If you want to change the default transition type, use the code below.
#
# transition_name("TRANSITION_NAME")
#
# Ex
#
# transition_name("BattleStart_4")
# transition_speed(160)

#==============================================================================
# example
# transition_ex(-1)
# transition_name("Transition_1")
# transition_speed(120)
#==============================================================================
# ● Histórico (Version History)
#==============================================================================
# v 1.4 - Melhoria na codificação.
#==============================================================================
module MOG_TRANSITION_EX


end

$imported = {} if $imported.nil?
$imported[:mog_transition_ex] = true

#===============================================================================
# ■ Game System
#===============================================================================
class Game_System
 
  attr_accessor :transition_ex
  attr_accessor :transition_name
  attr_accessor :transition_speed
 
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------   
  alias mog_transiton_ex_initialize initialize
  def initialize
      @transition_ex = 0
      @transition_name = "BattleStart"
      @transition_speed = 60
      mog_transiton_ex_initialize
  end
    
end

#==============================================================================
# ■ Game Interpreter
#==============================================================================
class Game_Interpreter
 
  #--------------------------------------------------------------------------
  # ● Transition EX
  #--------------------------------------------------------------------------       
  def transition_ex(type = 0)
      $game_system.transition_ex = type
  end 
 
  #--------------------------------------------------------------------------
  # ● Transition Name
  #--------------------------------------------------------------------------     
  def transition_name(name = "")
      $game_system.transition_name = name
  end 
 
  #--------------------------------------------------------------------------
  # ● Transition Speed
  #--------------------------------------------------------------------------       
  def transition_speed(speed = 60)
      $game_system.transition_speed = speed
  end 
 
end

#===============================================================================
# ■ SceneManager
#===============================================================================
class << SceneManager
 
  @background_transition = nil
 
  #--------------------------------------------------------------------------
  # ● Call
  #-------------------------------------------------------------------------- 
  alias mog_transition_ex_call call
  def call(scene_class)
      snapshot_for_transition
      mog_transition_ex_call(scene_class)   
  end
 
  #--------------------------------------------------------------------------
  # ● Snapshot For Transition
  #--------------------------------------------------------------------------
  def snapshot_for_transition
      @background_transition.dispose if @background_transition
      @background_transition = Graphics.snap_to_bitmap
  end
 
  #--------------------------------------------------------------------------
  # ● Background Transition
  #--------------------------------------------------------------------------
  def background_transition
      @background_transition
  end
 
end

#===============================================================================
# ■ Module Transition
#===============================================================================
module Module_Transition_EX
  include MOG_TRANSITION_EX
 
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------       
  def initialize
      super rescue nil
      execute_transition_ex
  end 
 
  #--------------------------------------------------------------------------
  # ● Terminate
  #--------------------------------------------------------------------------       
  def terminate
      super rescue nil
      dispose_transition_ex
  end
 
  #--------------------------------------------------------------------------
  # ● Create Black Background
  #--------------------------------------------------------------------------     
  def create_blackbackground
      return if @blackbackground != nil
      @blackbackground = Sprite.new
      @blackbackground.bitmap = Bitmap.new(Graphics.width,Graphics.height)
      @blackbackground.bitmap.fill_rect(0, 0, Graphics.width, Graphics.height, Color.new(0,0,0))
      @blackbackground.z = 5000
  end
 
  #--------------------------------------------------------------------------
  # ● Execute Transition EX
  #--------------------------------------------------------------------------   
  def execute_transition_ex
      return if @transtion_ex
      return if !$game_system.transition_ex.between?(0,6)
      @transition_ex = true
      dispose_transition_ex
      create_blackbackground
      @transition = []
      case $game_system.transition_ex   
        when 0
           @transition_time = 90
        else 
           @transition_time = 120
      end
      @transition.push(Sprite_Transition.new($game_system.transition_ex,@transition_time))
  end
 
 #--------------------------------------------------------------------------
 # ● Dispose Transition EX
 #--------------------------------------------------------------------------
 def dispose_transition_ex
     return if @transition == nil
     @transition.each {|sprite| sprite.dispose }
     @blackbackground.bitmap.dispose
     @blackbackground.dispose
     @transition_time = 0
     @transition = nil
 end 
 
 #--------------------------------------------------------------------------
 # ● Update Transition EX
 #--------------------------------------------------------------------------
 def update_transition_ex
     return if @transition == nil
     time = @transition_time
     for i in 0...@transition_time
           @transition.each {|sprite| sprite.update }
           @blackbackground.opacity -= 10 if time <= 26
           Graphics.update
           time -= 1
     end
     dispose_transition_ex
 end
 
end

#===============================================================================
# ■ Sprite Transition
#===============================================================================
class Sprite_Transition   
  include MOG_TRANSITION_EX
 
 #--------------------------------------------------------------------------
 # ● Initialize
 #--------------------------------------------------------------------------     
  def initialize(type = 0,duration = 90)
      @type = $game_system.transition_ex > 5 ? rand(5) : type
      @range = 0
      @speed = 0 
      @power = 0
      @image = SceneManager.background_transition
      @image = Cache.system("") if @image == nil
      @transition = Sprite.new     
      @transition.x = 0
      @transition.y = 0
      @transition.z = 99999
      @screen_size = [Graphics.width ,Graphics.height]
      @center = [@screen_size[0]/ 2, @screen_size[1] / 2]
      @transition.x = @center[0]
      @transition.y = @center[1]
      @transition.ox = @center[0]
      @transition.oy = @center[1]
      case @type
         when 5
            @transition.bitmap = Bitmap.new(@screen_size[0], @screen_size[1])         
            @transition.bitmap.stretch_blt(@transition.bitmap.rect, @image, @image.rect)                     
            @cw = @transition.bitmap.width
            @ch = @transition.bitmap.height / 2           
            src_rect = Rect.new(0, 0,@screen_size[0], @screen_size[1] )
            @transition.bitmap.blt(0, 0, @image, src_rect)                 
         else
            @transition.bitmap = Bitmap.new(@screen_size[0], @screen_size[1])         
            @transition.bitmap.stretch_blt(@transition.bitmap.rect, @image, @image.rect)                       
      end         
      @effect_time = [duration, duration]   
  end 
 
 #--------------------------------------------------------------------------
 # ● Dispose
 #--------------------------------------------------------------------------     
  def dispose
      @image.dispose
      @transition.bitmap.dispose
      @transition.dispose
  end 
 
 #--------------------------------------------------------------------------
 # ● Update
 #--------------------------------------------------------------------------   
  def update
      @effect_time[0] -= 1 if @effect_time[0] > 0
      case @type
         when 1 # Zoom IN / OUT # --------------------
               if  @effect_time[0].between?(@effect_time[1] - 20, @effect_time[1])
                   @transition.zoom_x += 0.07
                   @transition.zoom_y += 0.07
               else   
                   @transition.zoom_x -= 0.03
                   @transition.zoom_y -= 0.03
                   @transition.opacity -= 3
               end 
        when 2 # Angle # --------------------
                @transition.zoom_x += 0.01
                @transition.zoom_y -= 0.02
                @transition.opacity -= 2
                @transition.angle += 5
        when 3 # Wave
            if  @effect_time[0] == @effect_time[1] - 1
                @range = 250
                @speed = 500             
                @transition.wave_length = 544
            end
            @power += 1
            @transition.wave_amp = @power * 2
            @transition.wave_speed = @power * 7         
            @transition.opacity -= 2
            @transition.zoom_x += 0.01
            @transition.zoom_y += 0.01           
            @transition.update
        when 4 # Shake
            if  @effect_time[0].between?(@effect_time[1] - 10, @effect_time[1]) or
                @effect_time[0].between?(@effect_time[1] - 30, @effect_time[1] - 20) or
                @effect_time[0].between?(@effect_time[1] - 50, @effect_time[1] - 40) or
                @effect_time[0].between?(@effect_time[1] - 70, @effect_time[1] - 60) or
                @effect_time[0].between?(@effect_time[1] - 90, @effect_time[1] - 80)
                @transition.zoom_x += 0.1
                @transition.zoom_y += 0.1               
            else   
                @transition.zoom_x -= 0.1
                @transition.zoom_y -= 0.1
             end
        when 5 #Slice
           @transition.bitmap.clear
           @speed += 6           
           src_rect = Rect.new(0, 0,@cw, @ch )
           @transition.bitmap.blt(@speed, 0, @image, src_rect)           
           src_rect = Rect.new(0, @ch,@cw, @ch )
           @transition.bitmap.blt(-@speed, @ch, @image, src_rect)           
           @transition.opacity -= 3
           @transition.zoom_x += 0.005
           @transition.zoom_y += 0.005       
         else # Zoom IN # --------------------
              @transition.zoom_x += 0.05
              @transition.zoom_y += 0.05         
              @transition.opacity -= 3       
      end     
    end 
        
end

#===============================================================================
# ■ Scene Map
#===============================================================================
class Scene_Map < Scene_Base
 
 #--------------------------------------------------------------------------
 # ● Perform Battle Transition
 #--------------------------------------------------------------------------       
  def perform_battle_transition
     if $game_system.transition_ex.between?(0,6)       
        Graphics.transition(0)
      else
        Graphics.transition($game_system.transition_speed, "Graphics/System/" + $game_system.transition_name, 100)
     end
     Graphics.freeze     
  end

end

#===============================================================================
# ■ Scene Battle
#===============================================================================
class Scene_Battle < Scene_Base
  include Module_Transition_EX
 
 #--------------------------------------------------------------------------
 # ● Perform Transition
 #--------------------------------------------------------------------------       
 def perform_transition
     if $game_system.transition_ex.between?(0,6)
        Graphics.transition(0)
        update_transition_ex
     else       
        Graphics.transition($game_system.transition_speed, "Graphics/System/" + $game_system.transition_name, 100)
     end
     Graphics.update
 end
 
end
Another one that is different so I'm not sure what to do. It points me to the scene_map section but dispose doesn't work for it and terminate is a part of the scene_map (which I tried copying that part of).

So what is this sprite called? What is the reference to dispose of it?

Really surprising to find so many things. I'm just glad I'm working on finding problems vs making maps and developing the game. I don't want to make a whole game just to find memory leaks that could cause problems.
Did you edit that script in any way? If so, exactly what did you change/add?

There should be a file named gobj.txt in your project's folder. Delete it (make a copy of it if you need to, for backing up older logs), and trigger the console log again in the game. The file should re-appear in the project's folder. Copy the contents of it here.

I don't see any obvious parts in the script, although it is quite late for me, so I might miss some stuffs.
Gonna check it tomorrow, kinda busted for today, hunting for bugs in my giant scripts all day, need to rest the eyes. >.>
Spoiler: gobj text
Time: 2017-05-31 05:44:10 -0600
Memory Leak #<Sprite:0xf80d680>
In Scene Scene_Map
Creation Stack::
Script 0381 -- MOG | Transition_EX, Line: 164:in `create_blackbackground'
Script 0381 -- MOG | Transition_EX, Line: 178:in `execute_transition_ex'
Script 0381 -- MOG | Transition_EX, Line: 148:in `initialize'
Script 0006 -- SceneManager, Line: 60:in `new'
Script 0006 -- SceneManager, Line: 60:in `call'
Script 0380 -- MOG | Weather EX, Line: 932:in `call'
Script 0381 -- MOG | Transition_EX, Line: 117:in `call'
Script 0040 -- Game_Interpreter, Line: 1110:in `command_301'
Script 0222 -- VE | Multiple Troops, Line: 291:in `command_301'
Script 0040 -- Game_Interpreter, Line: 197:in `execute_command'
Script 0453 -- RPGMakerSource | Cutscene Skip, Line: 433:in `execute_command'
Script 0040 -- Game_Interpreter, Line: 103:in `run'
Script 0197 -- Shaz | Simple Mouse Script, Line: 984:in `run'
Script 0040 -- Game_Interpreter, Line: 60:in `block in create_fiber'
-----
Time: 2017-05-31 05:44:10 -0600
Memory Leak #<Sprite:0xf80d34c>
In Scene Scene_Map
Creation Stack::
Script 0381 -- MOG | Transition_EX, Line: 234:in `initialize'
Script 0381 -- MOG | Transition_EX, Line: 186:in `new'
Script 0381 -- MOG | Transition_EX, Line: 186:in `execute_transition_ex'
Script 0381 -- MOG | Transition_EX, Line: 148:in `initialize'
Script 0006 -- SceneManager, Line: 60:in `new'
Script 0006 -- SceneManager, Line: 60:in `call'
Script 0380 -- MOG | Weather EX, Line: 932:in `call'
Script 0381 -- MOG | Transition_EX, Line: 117:in `call'
Script 0040 -- Game_Interpreter, Line: 1110:in `command_301'
Script 0222 -- VE | Multiple Troops, Line: 291:in `command_301'
Script 0040 -- Game_Interpreter, Line: 197:in `execute_command'
Script 0453 -- RPGMakerSource | Cutscene Skip, Line: 433:in `execute_command'
Script 0040 -- Game_Interpreter, Line: 103:in `run'
Script 0197 -- Shaz | Simple Mouse Script, Line: 984:in `run'
Script 0040 -- Game_Interpreter, Line: 60:in `block in create_fiber'

I have not modified the script. I tried to after seeing this.

*EDIT if I move line 177 dispose_transition_ex down to the bottom of that section it get rid of the sprite dispose but then the battle transitions do not happen. It just goes straight to the battle scene. Also if I remove line 177, it is no different than when it is there.
It like the dispose part is not getting called at the right time. Ideas on where this should be.

*EDIT2 - nevermind. I think it is getting called and working properly, but it does the dispose after the battle is done. After exiting the battle the message does not show up when going into the menu like the other problem.

Original thread: https://forums.rpgmakerweb.com/threads/memory-leak-help-to-dispose-graphic.79284/