Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Disposing variables......

Disposing variables......

Scheduled Pinned Locked Moved C#
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hum Dum
    wrote on last edited by
    #1

    Hi all, The garbage collector runs in specific intervals(hope i am correct), and during this it collects all variable and dispose them when they becomes out of scope or not referred any more. a) In a particular Method() if i am creating many variables, then is it possible to dispose them all before exiting that method ? b)Suppose i have a method and inside this many methods, this MethodX execute till the last G() got executed and then it returns control to calling one.

    MethodX()
    {
    A();
    B();
    .
    .
    .
    G();//
    }

    But somehow its slowing the execution, Is it possible that all methods executed independently/simultaneously/parallely? regards,

    N S 2 Replies Last reply
    0
    • H Hum Dum

      Hi all, The garbage collector runs in specific intervals(hope i am correct), and during this it collects all variable and dispose them when they becomes out of scope or not referred any more. a) In a particular Method() if i am creating many variables, then is it possible to dispose them all before exiting that method ? b)Suppose i have a method and inside this many methods, this MethodX execute till the last G() got executed and then it returns control to calling one.

      MethodX()
      {
      A();
      B();
      .
      .
      .
      G();//
      }

      But somehow its slowing the execution, Is it possible that all methods executed independently/simultaneously/parallely? regards,

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Hum Dum wrote:

      The garbage collector runs in specific intervals

      It runs whenever cleanup is required.

      Hum Dum wrote:

      In a particular Method() if i am creating many variables, then is it possible to dispose them all before exiting that method ?

      If your variables are not referred and GC ran, it will get *collected*.

      Hum Dum wrote:

      But somehow its slowing the execution, Is it possible that all methods executed independently/simultaneously/parallely?

      Are you asking how to execute these methods in parallel? If yes, you need separate threads to execute each method. I am not sure how this is related to your actual GC question. :)

      Navaneeth How to use google | Ask smart questions

      1 Reply Last reply
      0
      • H Hum Dum

        Hi all, The garbage collector runs in specific intervals(hope i am correct), and during this it collects all variable and dispose them when they becomes out of scope or not referred any more. a) In a particular Method() if i am creating many variables, then is it possible to dispose them all before exiting that method ? b)Suppose i have a method and inside this many methods, this MethodX execute till the last G() got executed and then it returns control to calling one.

        MethodX()
        {
        A();
        B();
        .
        .
        .
        G();//
        }

        But somehow its slowing the execution, Is it possible that all methods executed independently/simultaneously/parallely? regards,

        S Offline
        S Offline
        Shyam K Pananghat
        wrote on last edited by
        #3

        A manuall call to GC.Collect is not recommended because it will do a full memmory compaction after the the collection process.. if you are using any heavy objects...Probably you can set is as null after use.. GC will get triggered only when the memmory pressure is more for a particular allocated heap. or when the allocated threashold limit is reached. You can used threading. But only after a good analysis upon your method structure ( that whether it is taking any input from the previus one) and requirement.. Remember Threading is there to use the CPU Idle time.it will take more time if it does't have any.

        Shyam.. My Blog dotnetscoups.blogspot.com

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups