Question on garbage collection (1 Viewer)

ziphnor

Retired Team Member
  • Premium Supporter
  • August 4, 2005
    755
    13
    Copenhagen
    Home Country
    Denmark Denmark
    Hi,

    Being annoyed with the problems with the Compress plug-in i decided to try to fix it. The problem is that whenever a transcoding job is in progress, the call GC.GetTotalMemory(true) doesnt return(at least within any reasonable time) when called in GUIWindow OnMessage when it gets a GUI_MSG_WINDOW_DEINIT message. This causes the effect that if you try to navigate away from the current window while the job is in progress, the gui blocks/locks.

    What i would like to know is a bit more about what the GC calls does. According to the documentation for GC.GetTotalMemory:

    Code:
            //
            // Summary:
            //     Retrieves the number of bytes currently thought to be allocated. A parameter
            //     indicates whether this method can wait a short interval before returning,
            //     to allow the system to collect garbage and finalize objects.
            //
            // Parameters:
            //   forceFullCollection:
            //     A Boolean value which, if true, indicates that this method can wait for garbage
            //     collection to occur before returning.
            //
            // Returns:
            //     A number that is the best available approximation of the number of bytes
            //     currently allocated in managed memory.

    From this it seems that it will a "short interval" before returning, but this doesnt seem to be the case. However this only happens when a transcoding job is in progress.

    I fixed the problem in my local installation by changing the call to GC.GetTotalMemory(false). Could the explanation be that the call waits for GC to finish, but GC might run with a very low priority so that it wont run because the transcoding job is eating up all the CPU time, locking the GUI which is waiting for it?

    I would also like to know why there are 3 call to GC.collect in a row preceding the call to GC.GetTotalMemory, why doesnt one suffice?
     

    draktheas

    Retired Team Member
  • Premium Supporter
  • December 17, 2005
    77
    2
    Generally speeking, it sounds like a resource contention issue. The transcoding is running in a seperate thread locking and unlocking resources and probably allocating/deallocating (indirectly) a lot of memory.

    One call to GC.Collect() should suffice for freeing all unreferenced memory. I don't know why three calls would be neccessary. The GC.GetTotalMemory call will need to temporarily lock any managed memory resources in order to obtain a snapshot of their size. My guess is that the transcoding thread is accessing a sufficient number of memory resources that it is gaining far more access to them than the GetTotalMemory call can, thus slowing down the call to GetTotalMemory.

    Just my 2 cents,
    Drak
     

    ziphnor

    Retired Team Member
  • Premium Supporter
  • August 4, 2005
    755
    13
    Copenhagen
    Home Country
    Denmark Denmark
    draktheas said:
    My guess is that the transcoding thread is accessing a sufficient number of memory resources that it is gaining far more access to them than the GetTotalMemory call can, thus slowing down the call to GetTotalMemory.

    You are probably right, its either memory of CPU resource contention. Isnt the logical consequence of this to stop calling GC.GetTotalMemory(true) at this point in the code? I mean, as far as i can tell its only there for debugging purposes, ie printing the amount of used memory to the log file. Also i feel that in general its poor style to have the GUI stall waiting for the garbage collector.

    Im new to messing around with the MP code, should i just submit a patch for the GUIWindow.cs file at sourceforge?
     

    draktheas

    Retired Team Member
  • Premium Supporter
  • December 17, 2005
    77
    2
    That's probably what I would do. But I am pretty new here, so I am not sure what the procedure for submitting a patch would be.

    Any Dev's want to take a stab at that one?

    Drak
     

    ziphnor

    Retired Team Member
  • Premium Supporter
  • August 4, 2005
    755
    13
    Copenhagen
    Home Country
    Denmark Denmark
    draktheas said:
    That's probably what I would do. But I am pretty new here, so I am not sure what the procedure for submitting a patch would be.

    Any Dev's want to take a stab at that one?

    Drak

    Well i tried creating a patch at sourceforge, i hope it did it correctly. I also created a seperate fix for the BlueTwo mytvcompress.xml skin which had set the wrong type for a control causing a null pointer exception.
     

    tomtom21000

    Retired Team Member
  • Premium Supporter
  • April 22, 2004
    1,226
    120
    Germany
    ziphnor said:
    [
    Well i tried creating a patch at sourceforge, i hope it did it correctly. I also created a seperate fix for the BlueTwo mytvcompress.xml skin which had set the wrong type for a control causing a null pointer exception.

    Just wanted to say that it went almost right. ;)
    Good description, but there are no files attached to your patches on sf.
    I am no programmer, so I can´t say much to the patches themselves.

    tomtom
     

    ziphnor

    Retired Team Member
  • Premium Supporter
  • August 4, 2005
    755
    13
    Copenhagen
    Home Country
    Denmark Denmark
    tomtom21000 said:
    Just wanted to say that it went almost right. ;)
    Good description, but there are no files attached to your patches on sf.
    I am no programmer, so I can´t say much to the patches themselves.

    :oops: However i see that they are now listed as closed, and looking in the CVS both patches seem to have been applied( the memory usage is now not printed at all, GC.collect is not called at all, and the skin button is correctly specified). I guess someone(most likely yamp, based on who closed it) read the description and made the changes based on that.

    I didnt forget the files, however, i didnt notice the checkbox you had to check of to actually get it to upload the file :)
     

    CoolHammer

    Retired Team Member
  • Premium Supporter
  • September 28, 2004
    174
    0
    Finland
    Hi,

    Thanks for your intrest of mediaportal. If you create other fixes i have found these tips useful when submitting code to the project.

    1. Submit whole files not just diffs.
    2. Open topic on forums with header [patch] short explanation
    3. And if possibe try to contact devs on irc (been silent lately tho)
    4. When submitting file describe your patch as much as possible.

    Hope these hints help you to submit your next patch.

    CoolHammer
     

    ziphnor

    Retired Team Member
  • Premium Supporter
  • August 4, 2005
    755
    13
    Copenhagen
    Home Country
    Denmark Denmark
    CoolHammer said:
    Hi,

    Thanks for your intrest of mediaportal. If you create other fixes i have found these tips useful when submitting code to the project.

    1. Submit whole files not just diffs.
    2. Open topic on forums with header [patch] short explanation
    3. And if possibe try to contact devs on irc (been silent lately tho)
    4. When submitting file describe your patch as much as possible.

    Hope these hints help you to submit your next patch.

    CoolHammer

    I got 1 and 4 covered this time(except i messed up in actually attaching the files, but then the descriptions were good enough that the patch could be done without the files :), i wasnt aware of the IRC developer chat nor the [patch] thread concept. Thanks for the information, i will heed you advice the next time i need to submit to submit a patch.
     

    Users who are viewing this thread

    Top Bottom