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. Destroy Variables

Destroy Variables

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netquestion
12 Posts 6 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.
  • S Shivan Nandan

    Dear friends, How can I destroy a variable in ASP.Net(C#). If anybody knows, please answer Regards Shivan

    Shivanandan C V

    M Offline
    M Offline
    mr_muskurahat
    wrote on last edited by
    #3

    i think variables are destroy after there scope is complete.... function () { var a; }---->here. why you need to destroy it??

    umerumerumer

    S S 2 Replies Last reply
    0
    • S Shivan Nandan

      Dear friends, How can I destroy a variable in ASP.Net(C#). If anybody knows, please answer Regards Shivan

      Shivanandan C V

      B Offline
      B Offline
      Brij
      wrote on last edited by
      #4

      Why you want this.Actually for any value type variable you does need to care because thaey are allocated n stack so they will be according to the scope of that variable. For reference type vaiable also ,the garbage collector take care of all this,you can also call garbage collector by your own but it is not advisable as per Microsoft.You can do one thing,if reference variablle if you don't need any more ,you can assign null it to you,it'll help gc.

      Cheers!! Brij

      N 1 Reply Last reply
      0
      • M mr_muskurahat

        i think variables are destroy after there scope is complete.... function () { var a; }---->here. why you need to destroy it??

        umerumerumer

        S Offline
        S Offline
        Shivan Nandan
        wrote on last edited by
        #5

        I am using dataTable to temporarily display data in GridView.So in my function I wrote code for adding fields and records. Then while running it for the second time, it displays error that column name already exists. So I think that the datatable is not getting cleared while stopping the program.

        Shivanandan C V

        N 1 Reply Last reply
        0
        • N Nishant Singh

          Assign null value to the variable .

          int i ;
          i=10;
          i=null ; //destroy variable

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

          Nishant Singh wrote:

          int i ; i=10; i=null ; //destroy variable

          Wrong. This will not compile. int can't have NULL value.

          Navaneeth How to use google | Ask smart questions

          1 Reply Last reply
          0
          • B Brij

            Why you want this.Actually for any value type variable you does need to care because thaey are allocated n stack so they will be according to the scope of that variable. For reference type vaiable also ,the garbage collector take care of all this,you can also call garbage collector by your own but it is not advisable as per Microsoft.You can do one thing,if reference variablle if you don't need any more ,you can assign null it to you,it'll help gc.

            Cheers!! Brij

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

            Brij wrote:

            if reference variablle if you don't need any more ,you can assign null it to you,it'll help gc.

            No.

            Navaneeth How to use google | Ask smart questions

            1 Reply Last reply
            0
            • S Shivan Nandan

              I am using dataTable to temporarily display data in GridView.So in my function I wrote code for adding fields and records. Then while running it for the second time, it displays error that column name already exists. So I think that the datatable is not getting cleared while stopping the program.

              Shivanandan C V

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

              How this data table object is declared? Looks like you have incorrectly declared the data table.

              Navaneeth How to use google | Ask smart questions

              S 1 Reply Last reply
              0
              • N N a v a n e e t h

                How this data table object is declared? Looks like you have incorrectly declared the data table.

                Navaneeth How to use google | Ask smart questions

                S Offline
                S Offline
                Shivan Nandan
                wrote on last edited by
                #9

                I have declared it as static DataTable dtMainTask = new DataTable();

                Shivanandan C V

                N 1 Reply Last reply
                0
                • S Shivan Nandan

                  I have declared it as static DataTable dtMainTask = new DataTable();

                  Shivanandan C V

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

                  Shivan Nandan wrote:

                  static

                  This is the problem. Do you know what is the scope for a static variable? It lives until the application domain unloads. BTW, is there any specific reason for declaring it as static?

                  Navaneeth How to use google | Ask smart questions

                  S 1 Reply Last reply
                  0
                  • N N a v a n e e t h

                    Shivan Nandan wrote:

                    static

                    This is the problem. Do you know what is the scope for a static variable? It lives until the application domain unloads. BTW, is there any specific reason for declaring it as static?

                    Navaneeth How to use google | Ask smart questions

                    S Offline
                    S Offline
                    Shivan Nandan
                    wrote on last edited by
                    #11

                    If I didnt declare it as static, then its value becomes empty in another function. ie, I declared it outside all the function , In Page_PreInit - declared the fields, In btnAdd_Click - wrote function to add rows Therefor if I didnt declare it as static then the fields are not accessible in btnAdd_Click function.

                    Shivanandan C V

                    1 Reply Last reply
                    0
                    • M mr_muskurahat

                      i think variables are destroy after there scope is complete.... function () { var a; }---->here. why you need to destroy it??

                      umerumerumer

                      S Offline
                      S Offline
                      scotchy2hotty2k2
                      wrote on last edited by
                      #12

                      The variables are automatically destroyed once they are out of there scope. If u are talking abt object.Let the asp.net garbage collector handle it for u.

                      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