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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Trivial (for u) q. about classes

Trivial (for u) q. about classes

Scheduled Pinned Locked Moved ASP.NET
questionperformancelounge
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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi, I know, I have a very stupid question, but please accept, that I've just created my first class in my life. And the question is, Must I set some of the variables declared in class to nothing or do something to free the memory in the end? (If so, please specify how). And also, when i write Dim myFirstClass as New FirstClass in the general declarations in page code, must I set this variable to nothing? Thanks

    C 1 Reply Last reply
    0
    • A Anonymous

      Hi, I know, I have a very stupid question, but please accept, that I've just created my first class in my life. And the question is, Must I set some of the variables declared in class to nothing or do something to free the memory in the end? (If so, please specify how). And also, when i write Dim myFirstClass as New FirstClass in the general declarations in page code, must I set this variable to nothing? Thanks

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Anonymous wrote: Must I set some of the variables declared in class to nothing or do something to free the memory in the end? No, you don't have to. The Garbage Collector will remove the objects when there are no references to them. Some classes have a Dispose() method and when you are finished with them, you should call Dispose() to clean up. This is because these classes contain references to native objects in the operating system that cannot be garbage collected. Of course, if you forget then it is normally no big deal, the finalizer will call dispose for you - however it does mean that the memory or resources will not be freed until the garbage collector gets to it. This could cause problems for things that are scarce resources. Anonymous wrote: And also, when i write Dim myFirstClass as New FirstClass in the general declarations in page code, must I set this variable to nothing? I'm not a VB.NET developer, but if I understand it correctly, the line of code you give will create a reference for an object and assign a new instance of the object to the reference. If you then set Nothing to the reference immediately after then you are wasting the processor's time by instantiating an object then immediately throwing it away. Does this help?


      "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

      C 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Anonymous wrote: Must I set some of the variables declared in class to nothing or do something to free the memory in the end? No, you don't have to. The Garbage Collector will remove the objects when there are no references to them. Some classes have a Dispose() method and when you are finished with them, you should call Dispose() to clean up. This is because these classes contain references to native objects in the operating system that cannot be garbage collected. Of course, if you forget then it is normally no big deal, the finalizer will call dispose for you - however it does mean that the memory or resources will not be freed until the garbage collector gets to it. This could cause problems for things that are scarce resources. Anonymous wrote: And also, when i write Dim myFirstClass as New FirstClass in the general declarations in page code, must I set this variable to nothing? I'm not a VB.NET developer, but if I understand it correctly, the line of code you give will create a reference for an object and assign a new instance of the object to the reference. If you then set Nothing to the reference immediately after then you are wasting the processor's time by instantiating an object then immediately throwing it away. Does this help?


        "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

        C Offline
        C Offline
        Chodici Mrkev
        wrote on last edited by
        #3

        Yes, you made it more clear for me, thanks.

        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