<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FlickDotNet.de - Holger&#039;s Take on Software Development &#187; 2010 &#187; April</title>
	<atom:link href="http://www.flickdotnet.de/index.php/2010/04/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flickdotnet.de</link>
	<description>Opinions, Reviews, Tutorials for Software Developers - Apple iOS, Microsoft .NET and Delphi</description>
	<lastBuildDate>Tue, 26 Jul 2011 17:32:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>NSString: Using stringWithFormat and left pad integers with zeros</title>
		<link>http://www.flickdotnet.de/index.php/2010/04/nsstring-using-stringwithformat-and-left-pad-integers-with-zeros/</link>
		<comments>http://www.flickdotnet.de/index.php/2010/04/nsstring-using-stringwithformat-and-left-pad-integers-with-zeros/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 04:41:07 +0000</pubDate>
		<dc:creator>holger</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.flickdotnet.de/?p=257</guid>
		<description><![CDATA[Today, I wanted to display a time-value of 9 minutes and 3 seconds like this: 09:03 Thus, I typed this snippet into my Objective-C code: labelTimer.text = [NSString stringWithFormat:@"%2d:%2d", minutes, seconds ]; [/code] This did not yield the result I wanted. The numbers were padded with spaces, not zeros. Sadly, Apple left out the options [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I wanted to display a time-value of 9 minutes and 3 seconds like this: <tt>09:03</tt></p>
<p>Thus, I typed this snippet into my Objective-C code:<br />
<code><br />
labelTimer.text = [NSString stringWithFormat:@"%2d:%2d", minutes, seconds ];<br />
[/code]</p>
<p>This did not yield the result I wanted. The numbers were padded with spaces, not zeros. Sadly, Apple left out the options for the different format specifiers like f, d, @ ... completely. You have to rely on old C skills in order to know how to pad with zeros or format decimal numbers the way you want. As a side-note, if you have a float and want to format it with 2 decimals, use <tt>%.2f</tt>. In order to pad zeros, you have to use <tt>%02d</tt> in this case, which leads to the following snippet in Objective-C code:</p>
<p></code><code><br />
labelTimer.text = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds ];<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flickdotnet.de/index.php/2010/04/nsstring-using-stringwithformat-and-left-pad-integers-with-zeros/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>libxml: Memory Management and leaks in Frameworks you consider &#8216;safe&#8217;</title>
		<link>http://www.flickdotnet.de/index.php/2010/04/libxml-memory-management-and-leaks-in-frameworks-you-consider-safe/</link>
		<comments>http://www.flickdotnet.de/index.php/2010/04/libxml-memory-management-and-leaks-in-frameworks-you-consider-safe/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 03:39:25 +0000</pubDate>
		<dc:creator>holger</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.flickdotnet.de/?p=255</guid>
		<description><![CDATA[If you have ever written code in Java or .NET, you will truly learn to appreciate the garbage collection, i.e. objects that are no longer referenced are being freed from memory. Automatically no less. A lot of people do not like it for reasons of their own and I do not want to get into [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code in Java or .NET, you will truly learn to appreciate the garbage collection, i.e. objects that are no longer referenced are being freed from memory. Automatically no less.</p>
<p>A lot of people do not like it for reasons of their own and I do <strong>not</strong> want to get into those.</p>
<p>What I do want to discuss is that in an environment in which you are responsible to allocate and free memory yourself (like Delphi, C++, Objective-C), you might stumble about issues with frameworks or base classes you use.</p>
<p>In my case it was the libxml part of the iPhone OS which allows you to parse XML documents. (I even now of Delphi developers using this library to parse large documents). Its biggest advantage is that the xml document is not read in one go but step-by-step in chunks. The developer can hook into it with an event-driven approach and can thus interpret the file. However, during the parse operation the library tends to produce memory leaks that cost me two hours of debugging.</p>
<p>With iPhone applications it is very simple: the iPhone is a mobile device with limited memory. If you produce too many leaks in a certain amount of time, you will not have many customers using your application as it might crash frequently (it might not even be accepted if you want to deploy to the Apple AppStore due to this fact). This makes you very aware of producing code that produces absolutely no memory leaks of any sort. Apple delivers Instruments so that you can debug your code for memory leaks. As I was not familiar with the tool, I did not realize at first that the leak did occur in the library and not in or because of code I had written.</p>
<p>Now comes the important part: formulate a rule. I do not want to waste another minute because of issues that are in 3rd party code. However, it is not as easy, because it might not be the 3rd party library but you not handing over the data to the library correctly (especially when dealing with different languages and use DLLs e.g.). To state the rule &#8216;Always check the call stack where the leak originates.&#8217; will not suffice. An example for this is that you allocate memory for an object instance and then hand a reference to this instance to a function or method. The method allocates memory again and returns another reference instead of using the one you provided. In that case you are responsible for the leak. Documentation needs to be clear in cases like this.</p>
<p>I think that fact is the biggest pro for garbage collection. Some people might call it lazy, but I prefer it considering how much time I spent when writing iPhone applications thinking  of proper memory management. iPhone OS comes with strict guidelines how to name methods so that you know if the caller or the function is responsible to allocate and free the memory which makes it easier, but it is still difficult enough.</p>
<p>As a final point, please be aware that my googling and analysis really points to a method in the parser of libxml leaking some bytes when parsing a document. In case you develop an iPhone app and use libxml, do not worry about the leaks that Instruments shows you that derive from a call to the parse mehod of the xml parser &#8212; not your fault.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flickdotnet.de/index.php/2010/04/libxml-memory-management-and-leaks-in-frameworks-you-consider-safe/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

