Click here to Skip to main content
16,015,531 members
Home / Discussions / C#
   

C#

 
GeneralRe: Optimization Pin
Paul Conrad27-Jan-08 9:56
professionalPaul Conrad27-Jan-08 9:56 
GeneralRe: Optimization Pin
Luc Pattyn27-Jan-08 6:35
sitebuilderLuc Pattyn27-Jan-08 6:35 
GeneralRe: Optimization Pin
half-life27-Jan-08 7:07
half-life27-Jan-08 7:07 
GeneralRe: Optimization Pin
Luc Pattyn27-Jan-08 7:34
sitebuilderLuc Pattyn27-Jan-08 7:34 
GeneralRe: Optimization Pin
half-life27-Jan-08 8:38
half-life27-Jan-08 8:38 
GeneralRe: Optimization Pin
Luc Pattyn27-Jan-08 8:53
sitebuilderLuc Pattyn27-Jan-08 8:53 
GeneralRe: Optimization Pin
half-life27-Jan-08 9:53
half-life27-Jan-08 9:53 
GeneralRe: Optimization Pin
PIEBALDconsult27-Jan-08 7:39
mvePIEBALDconsult27-Jan-08 7:39 
Yeah, that's one (or two) of the things he meant.

That instance has local scope, so when the function exits it will be garbage collected... eventually.
If that doesn't happen in a timely manner, and you call this function frequently, you could be wasting memory with a bunch of these instances.

So, if the class is Disposable, either call Dispose before exitting the function, or use the using statement (not the same as the using directive).

Alternatively, you could add a field (perhaps static) to your class that will hold onto the instance for a much longer time, this technique has the added benefit of reducing the overhead you incur with instantiating and disposing the object repeatedly.
GeneralRe: Optimization Pin
half-life27-Jan-08 8:41
half-life27-Jan-08 8:41 
GeneralRe: Optimization Pin
Luc Pattyn27-Jan-08 9:21
sitebuilderLuc Pattyn27-Jan-08 9:21 
GeneralRe: Optimization Pin
half-life27-Jan-08 9:54
half-life27-Jan-08 9:54 
GeneralRe: Optimization Pin
PIEBALDconsult27-Jan-08 10:47
mvePIEBALDconsult27-Jan-08 10:47 
QuestionShare source code of C# Pin
kelary27-Jan-08 2:51
kelary27-Jan-08 2:51 
GeneralRe: Share source code of C# Pin
Giorgi Dalakishvili27-Jan-08 3:00
mentorGiorgi Dalakishvili27-Jan-08 3:00 
GeneralRe: Share source code of C# Pin
Paul Conrad27-Jan-08 5:50
professionalPaul Conrad27-Jan-08 5:50 
QuestionHow to Represent String Constants Pin
Brady Kelly27-Jan-08 0:11
Brady Kelly27-Jan-08 0:11 
AnswerRe: How to Represent String Constants Pin
PIEBALDconsult27-Jan-08 4:15
mvePIEBALDconsult27-Jan-08 4:15 
GeneralRe: How to Represent String Constants Pin
Brady Kelly27-Jan-08 4:49
Brady Kelly27-Jan-08 4:49 
GeneralRe: How to Represent String Constants Pin
PIEBALDconsult27-Jan-08 7:49
mvePIEBALDconsult27-Jan-08 7:49 
GeneralRe: How to Represent String Constants Pin
Brady Kelly27-Jan-08 8:06
Brady Kelly27-Jan-08 8:06 
GeneralResolution and Icon Layout Pin
half-life26-Jan-08 23:34
half-life26-Jan-08 23:34 
Question[Message Deleted] Pin
methhoo26-Jan-08 23:32
methhoo26-Jan-08 23:32 
GeneralRe: manipulate a web page with a C# application ? Pin
Ravi Bhavnani27-Jan-08 8:07
professionalRavi Bhavnani27-Jan-08 8:07 
GeneralAccessing files in a network share Pin
clint198226-Jan-08 22:16
clint198226-Jan-08 22:16 
GeneralRe: Accessing files in a network share Pin
Judah Gabriel Himango27-Jan-08 9:27
sponsorJudah Gabriel Himango27-Jan-08 9:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.