managed code?

Discussion in 'MCSD' started by Edward, Nov 22, 2004.

  1. Edward

    Edward Guest

    I was going through the examples in the C# book for 316. As a VB6.0, Fortran
    and C++ programmer I was troubled by what I was doing. Below is a short
    example I wrote to demonstrate my puzzlement.



    Is this good coding in a managed environment? Just create new objects on the
    heap and ignore them when you are done? Will they be taken care of when the
    system does clean up? Shouldn't I destroy them myself?



    for (int i = 0 ; i < 10; i++)

    {

    int p = new int();

    p = i;

    System.Console.WriteLine (place);

    }





    Thanks for the help



    Edward
    Edward, Nov 22, 2004
    #1
    1. Advertising

  2. Edward

    Edward Guest

    for (int i = 0 ; i < 10; i++)

    {

    int p = new int();

    p = i;

    System.Console.WriteLine (p); // forgot to change this variable to p also
    Edward sorry

    }

    "Edward" <> wrote in message
    news:...
    >I was going through the examples in the C# book for 316. As a VB6.0,
    >Fortran and C++ programmer I was troubled by what I was doing. Below is a
    >short example I wrote to demonstrate my puzzlement.
    >
    >
    >
    > Is this good coding in a managed environment? Just create new objects on
    > the heap and ignore them when you are done? Will they be taken care of
    > when the system does clean up? Shouldn't I destroy them myself?
    >
    >
    >
    > for (int i = 0 ; i < 10; i++)
    >
    > {
    >
    > int p = new int();
    >
    > p = i;
    >
    > System.Console.WriteLine (place);
    >
    > }
    >
    >
    >
    >
    >
    > Thanks for the help
    >
    >
    >
    > Edward
    >
    >
    Edward, Nov 22, 2004
    #2
    1. Advertising

  3. Edward

    Nick Guest

    Yep, that should be ok afaik.

    The difficulty comes when you are using types defined in unmanaged code.

    Then you have to implement the dispose pattern and clean up after yourself.

    "Edward" <> wrote in message
    news:...
    > for (int i = 0 ; i < 10; i++)
    >
    > {
    >
    > int p = new int();
    >
    > p = i;
    >
    > System.Console.WriteLine (p); // forgot to change this variable to p also
    > Edward sorry
    >
    > }
    >
    > "Edward" <> wrote in message
    > news:...
    >>I was going through the examples in the C# book for 316. As a VB6.0,
    >>Fortran and C++ programmer I was troubled by what I was doing. Below is a
    >>short example I wrote to demonstrate my puzzlement.
    >>
    >>
    >>
    >> Is this good coding in a managed environment? Just create new objects on
    >> the heap and ignore them when you are done? Will they be taken care of
    >> when the system does clean up? Shouldn't I destroy them myself?
    >>
    >>
    >>
    >> for (int i = 0 ; i < 10; i++)
    >>
    >> {
    >>
    >> int p = new int();
    >>
    >> p = i;
    >>
    >> System.Console.WriteLine (place);
    >>
    >> }
    >>
    >>
    >>
    >>
    >>
    >> Thanks for the help
    >>
    >>
    >>
    >> Edward
    >>
    >>

    >
    >
    Nick, Nov 23, 2004
    #3
  4. Edward

    Edward Guest

    Well after years and years of cleaning up after myself, this managed code
    just makes me nervous.


    "Nick" <> wrote in message
    news:e$...
    > Yep, that should be ok afaik.
    >
    > The difficulty comes when you are using types defined in unmanaged code.
    >
    > Then you have to implement the dispose pattern and clean up after
    > yourself.
    >
    > "Edward" <> wrote in message
    > news:...
    >> for (int i = 0 ; i < 10; i++)
    >>
    >> {
    >>
    >> int p = new int();
    >>
    >> p = i;
    >>
    >> System.Console.WriteLine (p); // forgot to change this variable to p
    >> also Edward sorry
    >>
    >> }
    >>
    >> "Edward" <> wrote in message
    >> news:...
    >>>I was going through the examples in the C# book for 316. As a VB6.0,
    >>>Fortran and C++ programmer I was troubled by what I was doing. Below is a
    >>>short example I wrote to demonstrate my puzzlement.
    >>>
    >>>
    >>>
    >>> Is this good coding in a managed environment? Just create new objects on
    >>> the heap and ignore them when you are done? Will they be taken care of
    >>> when the system does clean up? Shouldn't I destroy them myself?
    >>>
    >>>
    >>>
    >>> for (int i = 0 ; i < 10; i++)
    >>>
    >>> {
    >>>
    >>> int p = new int();
    >>>
    >>> p = i;
    >>>
    >>> System.Console.WriteLine (place);
    >>>
    >>> }
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> Thanks for the help
    >>>
    >>>
    >>>
    >>> Edward
    >>>
    >>>

    >>
    >>

    >
    >
    Edward, Nov 23, 2004
    #4
  5. Edward

    Jon Goodwin Guest

    Edward,
    Have a look at the following URL:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/dotnetGCbasics.asp
    It explains how .NET implements garbage collection and why you should
    never need to worry about cleaning up after yourself again!

    Edward wrote:
    > Well after years and years of cleaning up after myself, this managed code
    > just makes me nervous.
    >
    >
    > "Nick" <> wrote in message
    > news:e$...
    >
    >>Yep, that should be ok afaik.
    >>
    >>The difficulty comes when you are using types defined in unmanaged code.
    >>
    >>Then you have to implement the dispose pattern and clean up after
    >>yourself.
    >>
    >>"Edward" <> wrote in message
    >>news:...
    >>
    >>>for (int i = 0 ; i < 10; i++)
    >>>
    >>>{
    >>>
    >>>int p = new int();
    >>>
    >>>p = i;
    >>>
    >>>System.Console.WriteLine (p); // forgot to change this variable to p
    >>>also Edward sorry
    >>>
    >>>}
    >>>
    >>>"Edward" <> wrote in message
    >>>news:...
    >>>
    >>>>I was going through the examples in the C# book for 316. As a VB6.0,
    >>>>Fortran and C++ programmer I was troubled by what I was doing. Below is a
    >>>>short example I wrote to demonstrate my puzzlement.
    >>>>
    >>>>
    >>>>
    >>>>Is this good coding in a managed environment? Just create new objects on
    >>>>the heap and ignore them when you are done? Will they be taken care of
    >>>>when the system does clean up? Shouldn't I destroy them myself?
    >>>>
    >>>>
    >>>>
    >>>> for (int i = 0 ; i < 10; i++)
    >>>>
    >>>> {
    >>>>
    >>>> int p = new int();
    >>>>
    >>>> p = i;
    >>>>
    >>>> System.Console.WriteLine (place);
    >>>>
    >>>> }
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>Thanks for the help
    >>>>
    >>>>
    >>>>
    >>>>Edward
    >>>>
    >>>>
    >>>
    >>>

    >>

    >
    >
    Jon Goodwin, Nov 23, 2004
    #5
  6. Edward

    clyclopedic Guest

    I haven't watched it yet, but from the blurbs I think you might also be
    interested in the Jason Zander interview posted to channel 9 today
    http://channel9.msdn.com/

    "Jon Goodwin" <> wrote in message
    news:...
    > Edward,
    > Have a look at the following URL:
    > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/dotnetGCbasics.asp
    > It explains how .NET implements garbage collection and why you should
    > never need to worry about cleaning up after yourself again!
    >
    > Edward wrote:
    >> Well after years and years of cleaning up after myself, this managed code
    >> just makes me nervous.
    >>
    >>
    >> "Nick" <> wrote in message
    >> news:e$...
    >>
    >>>Yep, that should be ok afaik.
    >>>
    >>>The difficulty comes when you are using types defined in unmanaged code.
    >>>
    >>>Then you have to implement the dispose pattern and clean up after
    >>>yourself.
    >>>
    >>>"Edward" <> wrote in message
    >>>news:...
    >>>
    >>>>for (int i = 0 ; i < 10; i++)
    >>>>
    >>>>{
    >>>>
    >>>>int p = new int();
    >>>>
    >>>>p = i;
    >>>>
    >>>>System.Console.WriteLine (p); // forgot to change this variable to p
    >>>>also Edward sorry
    >>>>
    >>>>}
    >>>>
    >>>>"Edward" <> wrote in message
    >>>>news:...
    >>>>
    >>>>>I was going through the examples in the C# book for 316. As a VB6.0,
    >>>>>Fortran and C++ programmer I was troubled by what I was doing. Below is
    >>>>>a short example I wrote to demonstrate my puzzlement.
    >>>>>
    >>>>>
    >>>>>
    >>>>>Is this good coding in a managed environment? Just create new objects
    >>>>>on the heap and ignore them when you are done? Will they be taken care
    >>>>>of when the system does clean up? Shouldn't I destroy them myself?
    >>>>>
    >>>>>
    >>>>>
    >>>>> for (int i = 0 ; i < 10; i++)
    >>>>>
    >>>>> {
    >>>>>
    >>>>> int p = new int();
    >>>>>
    >>>>> p = i;
    >>>>>
    >>>>> System.Console.WriteLine (place);
    >>>>>
    >>>>> }
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>Thanks for the help
    >>>>>
    >>>>>
    >>>>>
    >>>>>Edward
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>

    >>
    >>

    >
    clyclopedic, Nov 23, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alp
    Replies:
    0
    Views:
    523
  2. SpiritBoy

    Inexpensive access points that can be centrally managed

    SpiritBoy, Mar 31, 2005, in forum: Wireless Networking
    Replies:
    0
    Views:
    508
    SpiritBoy
    Mar 31, 2005
  3. hairbrash

    Cisco 837 Managed Ethernet?

    hairbrash, Apr 15, 2004, in forum: Cisco
    Replies:
    7
    Views:
    3,335
    hairbrash
    Apr 17, 2004
  4. Ned Hart
    Replies:
    5
    Views:
    513
    Farouq Taj
    May 13, 2004
  5. xlr8
    Replies:
    1
    Views:
    567
    Russell Lusignan
    Aug 19, 2004
Loading...

Share This Page