Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computer Certification > MCSD > managed code?

Reply
Thread Tools

managed code?

 
 
Edward
Guest
Posts: n/a
 
      11-22-2004
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


 
Reply With Quote
 
 
 
 
Edward
Guest
Posts: n/a
 
      11-22-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>
>



 
Reply With Quote
 
 
 
 
Nick
Guest
Posts: n/a
 
      11-23-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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
>>
>>

>
>



 
Reply With Quote
 
Edward
Guest
Posts: n/a
 
      11-23-2004
Well after years and years of cleaning up after myself, this managed code
just makes me nervous.


"Nick" <(E-Mail Removed)> wrote in message
news:e$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>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
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Jon Goodwin
Guest
Posts: n/a
 
      11-23-2004
Edward,
Have a look at the following URL:
http://msdn.microsoft.com/library/de...etGCbasics.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" <(E-Mail Removed)> wrote in message
> news:e$(E-Mail Removed)...
>
>>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" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed)...
>>
>>>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" <(E-Mail Removed)> wrote in message
>>>news:(E-Mail Removed)...
>>>
>>>>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
>>>>
>>>>
>>>
>>>

>>

>
>


 
Reply With Quote
 
clyclopedic
Guest
Posts: n/a
 
      11-23-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Edward,
> Have a look at the following URL:
> http://msdn.microsoft.com/library/de...etGCbasics.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" <(E-Mail Removed)> wrote in message
>> news:e$(E-Mail Removed)...
>>
>>>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" <(E-Mail Removed)> wrote in message
>>>news:(E-Mail Removed)...
>>>
>>>>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" <(E-Mail Removed)> wrote in message
>>>>news:(E-Mail Removed).. .
>>>>
>>>>>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
>>>>>
>>>>>
>>>>
>>>>
>>>

>>
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inexpensive access points that can be centrally managed SpiritBoy Wireless Networking 0 03-31-2005 03:27 PM
AWLP turns your PC into web-managed wireless access gateway Alp Wireless Networking 0 01-04-2005 10:47 AM
Memory Allication (Managed VC++ DLL to Unmanaged DLL) [Second Try] Weston Fryatt ASP .Net 2 01-01-2005 11:31 AM
HELP !!! Managed C++, WinForms and ATL !!! Dmitry ASP .Net 0 11-01-2004 07:27 PM
Managed Code??? Manoj Mohan ASP .Net 4 09-25-2003 09:36 AM



Advertisments