Results 1 to 7 of 7

Thread: Freeing resources

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    5

    Freeing resources

    When programming normal OpenGL in C++ I always take care to wrap every OpenGL object (textures, VBOs, FBOs etc') with an automatic class that deallocates it on the destructor.
    With WebGL As I understand it, the garbage collector does this for me when there are no more references to that object.
    So is there any real benefit to calling deleteBuffer explicitly when I know I'm done with it?

  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: Freeing resources

    Yes and no. The Javascript garbage collector will indeed remove the thing for you...eventually. The difficulty is that you really have no idea when. Since these buffers often represent a large chunk of memory, you might want to make sure that it's freed when YOU want it freed. For example, you might have a particularly timing-critical bit of code (like playing a sound, for example) and it might be especially bad if you ran out of free memory and thereby triggered the garbage collector right as you started to play it. Getting rid of these large buffers as soon as you know you don't need them anymore is a good thing because it guarantees that there is room for small allocations elsewhere.

    That said, garbage collection is an evil thing that's provided for the weak-minded! It's a pain in the butt that the garbage collector can trigger at any time and consume a huge chunk of your CPU budget with no way for you to schedule that...so, sadly, you're going to take occasional random memory hits no matter what you do.

  3. #3

    Re: Freeing resources

    yep I hate garbage collection also, I see these micro pauses during app execution that are caused by this.

    One thing Ive found which helps is keep a few global structures around eg
    var globalLS = new LINESEGMENT();
    var globalVec3 = new Vec3();

    when you want to use a temporary variable use one of these, instead of creating a local one

    also firefox is terrible WRT garbage collection compared to chrome, eg from what I see, press F5 in FF it doesnt clear out all the used memory! thus after a few F5's your app is > 1GB! normally I cant go 1 hour without having to quit FF are restarting

  4. #4
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: Freeing resources

    F5 (or Ctrl-R) only reloads the document - it makes no claims for clearing out the cache. Use Shift-F5 (or Ctrl-Shift-R) to reload...overriding the cache. However, even that doesn't solidly clear the cache for files that your JavaScript loads using HTTP after the page is loaded (you said "reload THIS page without using the cache" - but once it's reloaded, the cache still has those files that YOU loaded in your code).

    The only thing that I've found that properly ensures that you're getting all of your files freshly from the server is to go to the Tools/ClearRecentHistory... dialog, unchecking everything except "Cache", setting the "TimeRangeToClear" to "Everything" and hitting the "ClearNow" button.

    Actually, I've found Chrome to be even more prone to holding on to stuff in the cache than Firefox and I've had to resort to exiting the browser and manually deleting all of the cache files! (Although this 'stuck cache' thing last happened to me several months ago - and it may be that it's fixed in more recent versions).

  5. #5
    Junior Member
    Join Date
    Feb 2011
    Posts
    5

    Re: Freeing resources

    FF garbage collector does seem to suck. This actually explains now the little hangs I get every few seconds.

    Is there some tool or something that can tell me what is the garbage collector doing so I could know where to focus my efforts?

  6. #6

    Re: Freeing resources

    you code try profiling your code (with chrome) + looking at the tree view to see if its actually the GC thats actually causing the hangs.
    Like I said try to use a few global variables (that wont get destroyed after use) instead of local variables

    PS - Im more than a bit pissed of with chrome as its stopped working again with webgl (it crashes instantly, Im pissed off since I had enabled 'do not update chrome from the internet' thus it expressly ignored my command. Once I get it working again I think the only option is to firewall chrome completely from the internet.

    chrome does seem to have far better memory usage than firefox.
    from new restart of chrome/firefox
    chrome ~60mb used -> Shift-F5 (or Ctrl-Shift-R) ~60mb + constant with each restart
    firefox ~150mb used -> Shift-F5 (or Ctrl-Shift-R) ~250mb + steadly climbs with each restart

  7. #7

    Re: Freeing resources

    Update (should be an edit)
    firefox beta 12 solves a lot of the memory issues. i.e you can now press F5 + current used memory gets cleaned up eventually, performance is also improved from the last version I tested ~30%.
    Also chrome has started working again (no automatic updates must only be a suggestion not a command), so Ive now firewalled it from accessing the internet

Similar Threads

  1. Out of resources problem
    By GankevichIvan in forum OpenCL
    Replies: 5
    Last Post: 07-08-2010, 04:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •