November 2008 Entries

Solving memory leak in javascript with try-finally

In my previous post, I discussed how return statement is executed in try-finally clause. So in following program: string str = "original string"; try { return str; } finally { str = "changed in finally"; } the original value will be returned instead of the value changed in finally block. Would this feature be useful anywhere? Well, I can’t find anything in C#, but I can think up an example in javascript. First, let’s have a look of following javascrip code: function createDiv() { var div = document.createElement("div"); ......

Posted On Saturday, November 29, 2008 11:59 AM | Comments (5)

Code smell – many usings

Normal 0 false false false EN-US ZH-CN X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; ......

Posted On Friday, November 28, 2008 9:55 AM | Comments (3)

C# quiz - try-finally

So what is the output for following program? public class SimpleTest { public static void Main(string[] args) { Console.WriteLine(GetString... Console.ReadLine(); } private static string GetString() { string str = "original string"; try { return str; } finally { str = "changed in finally"; } } } It looks very simple, but most of my developer friends and I all had the wrong answer. In the college, we were all told that finally block is guaranteed to be executed before a method returns, right? So ......

Posted On Thursday, November 27, 2008 9:01 PM | Comments (12)

Copyright © Changhong Fu

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski