Re: general performance question



Clearly there's no sense at any time in creating an object and then setting
it to null

Sometimes I declare a variable that is to point to a resource and set
it to null so that the resource can be released in a wider scope. For
example:

Connection conn = null;
try {
conn = ConnectionFactory.getConnection();
doSomethingWithTheConnection(conn);
} finally {
if(conn != null) {
conn.close();
}
}

The best practice is to not fool with this kind of optimization unless you
have hard data from a profiler that it's actually a problem.

Whole heartedly agree. On occasion, some will throw out performance
as an excuse when backed into a corner or feel that they must give
some sort of explanation. If a performance hit is claimed it should
be backed up with some kind of measurement.

John
.



Relevant Pages

  • Re: general performance question
    ... Sometimes I declare a variable that is to point to a resource and set ... Connection conn = null; ... If a performance hit is claimed it should ... final Connection connection = getConnections; ...
    (comp.lang.java.programmer)
  • Re: best practice for variable declaration
    ... have been more economical to declare variable here after the if block. ... connection from the pool as occupied even though it may not necessarily be. ... either the if block executes and returns without closing the connection or ... The resource wastefullness of this approach is compounded for more ...
    (microsoft.public.dotnet.framework)
  • Re: SORN petition
    ... you may sell it and not declare the sale ... forgetting to stick to the speed limit should not be a fine either? ... thats not a lot of resource. ...
    (uk.rec.motorcycles.classic)
  • Re: Is it possible to edit the font in a single text box?
    ... performance hit of initializing frequently which could happen. ... your resource into the RichTextBox just once in the Form's Load event. ... rtf file and on my machine the combined total time of loading the rtf data ... and that includes the time it takes for the RTB to format the ...
    (microsoft.public.vb.general.discussion)
  • Re: Is it possible to edit the font in a single text box?
    ... performance hit of initializing frequently which could happen. ... your resource into the RichTextBox just once in the Form's Load event. ... I've just timed the act of doing exactly that job using a typical medium sized rtf file and on my machine the combined total time of loading the rtf data from the resource file and then dropping into an RTB takes about half a millisecond, and that includes the time it takes for the RTB to format the data! ...
    (microsoft.public.vb.general.discussion)