Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GarbageCollector disposing of GraphicsBuffer

Discussion in 'Shaders' started by EpicMcDude, Aug 23, 2021.

  1. EpicMcDude

    EpicMcDude

    Joined:
    Apr 15, 2013
    Posts:
    117
    Hi all,

    I've been having this error since the beginning of my project, and now I wanted to ask for help because I'm not sure how to fix them as I lack the proper experience to do so!

    This error (warning)
    GarbageCollector disposing of GraphicsBuffer. Please use GraphicsBuffer.Release() or .Dispose() to manually release the buffer.
    UnityEngine.GraphicsBuffer:Finalize ()
    is actually creating a GPU memory leak which is crashing my PC/Unity Editor after a various tests of the game or if I have it on Play mode for a bit. Also happens when I make a build of the game, the computer will crash after around 20 minutes playing it which is causing problems everyone testing my game.

    I do not know what disposing of GraphicsBuffer entails, or how/where I would use GraphicsBuffer.Release or Dispose(). I am using this PS1 Shader from the asset store, but the creator of the asset is unresponsive to my emails so I can't get his help.

    Would you know if it's possible to just write the line of code GraphicsBuffer.Release() or .Dispose() in the shader script?

    Thanks!
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    You just need to look into the asset's code for where they are creating the GraphicsBuffer and then where the end of the code is that uses it (assuming they're not assigning it to a class field).

    At the end of the code, you can call
    whateverGraphicsBufferVariableNameIs.Release();


    Also, are you sure the error is coming from that asset? If you double click the error, what script does it lead you to?
     
    Last edited: Aug 23, 2021
  3. EpicMcDude

    EpicMcDude

    Joined:
    Apr 15, 2013
    Posts:
    117
    Hmm, I tried finding the GraphicsBuffer on the asset's scripts with CTRL + F but there's nothing in the scripts that calls this function.
    I can't go directly to the script by double clicking it because when I double click the error, nothing happens, it doesn't take me to any script in particular like it should.

    But I do know it's due to this shader because every time I delete it from my project, the error is gone.
    But worth noting that I use this shader in another project and that one does not have this GraphicsBuffer.Release issue, there's no memory leak of any kind there.

    EDIT: Well, turns out it's not actually the shader causing an issue, I deleted the asset once again, and the error came back much later than usual.

    So I'm guessing this is a unity issue? I've tried three different versions of the unity editor, 2020.3.7, 2020.3.16, 2021.1, all had the same issue.
     
    Last edited: Aug 23, 2021
  4. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    Have you tried a fresh project? It may be something else in your project you're using.
    Are you using URP or HDRP? I know in earlier iterations they often threw errors like that and thus you might need to update the package for the one you're using if so.
     
    EpicMcDude likes this.
  5. EpicMcDude

    EpicMcDude

    Joined:
    Apr 15, 2013
    Posts:
    117
    Yup, yesterday I made a new project and imported over every asset one-by-one, testing the game in Play mode each time to see if the error would pop-up but it seems like clean project fixed the bug!
    I was dreading doing it this way, just because it would time consuming but it was worth.

    Thank you for the help!
     
    Invertex likes this.