<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Murad Al Wajed on Medium]]></title>
        <description><![CDATA[Stories by Murad Al Wajed on Medium]]></description>
        <link>https://medium.com/@muradwajed?source=rss-bc0f2f440fd7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ekcY2FS5Vp0qL2i4bKWk9A.jpeg</url>
            <title>Stories by Murad Al Wajed on Medium</title>
            <link>https://medium.com/@muradwajed?source=rss-bc0f2f440fd7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 14:50:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@muradwajed/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Avoiding Memory Leaks in iOS]]></title>
            <link>https://medium.com/@muradwajed/avoiding-memory-leaks-in-ios-c44ecf97f99?source=rss-bc0f2f440fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/c44ecf97f99</guid>
            <dc:creator><![CDATA[Murad Al Wajed]]></dc:creator>
            <pubDate>Tue, 29 Aug 2023 14:09:35 GMT</pubDate>
            <atom:updated>2023-08-29T14:09:35.124Z</atom:updated>
            <content:encoded><![CDATA[<p>Memory leaks can have a detrimental impact on your iOS applications. They can lead to increased memory consumption, reduced performance, and in worst cases, app crashes. Fortunately, iOS provides tools and best practices to help identify and fix these leaks. This article dives into understanding memory leaks and ways to prevent them in iOS apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4oxAxp6Oq9J0Cqyf" /><figcaption>Photo by <a href="https://unsplash.com/@afgprogrammer?utm_source=medium&amp;utm_medium=referral">Mohammad Rahmani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What is a Memory Leak?</h3><p>In iOS development, a memory leak occurs when an object is retained in memory but cannot be accessed or released. Over time, as more and more memory is leaked, the app can consume significant amounts of memory, leading to performance issues.</p><h3>Causes of Memory Leaks:</h3><ol><li><strong>Retain Cycles: </strong>This is the most common cause of memory leaks in iOS. It occurs when two objects hold strong references to each other, preventing them from being deallocated.</li><li><strong>Singletons:</strong> These can sometimes lead to memory leaks, especially if they hold strong references to other objects that aren’t getting deallocated.</li><li><strong>Closures: </strong>Closures can capture and store references to any constants and variables from the context in which they are defined. If they capture objects strongly, they can lead to memory leaks.</li><li><strong>Delegates:</strong> If a delegate property is referenced strongly, it can lead to a retain cycle.</li></ol><h3>Tips to Avoid Memory Leaks:</h3><ol><li><strong>Use Weak or Unowned References:</strong> To break the retain cycle, you can use weak or unowned references. While both are used to break strong reference cycles, weak references turn nil when the object it references is deallocated, while unowned expects the object it references to never become nil.</li><li><strong>Be Cautious with Closures:</strong> Ensure that any objects captured within closures are referenced as [weak self] or [unowned self].</li><li><strong>Delegate Properties Should be Weak:</strong> By default, delegate properties should be weak to avoid creating a retain cycle.</li><li><strong>Use Instruments:</strong> The ‘Leaks’ tool in Instruments is invaluable in tracking down memory leaks. It provides a visual representation of the memory being used by your app and can help pinpoint where leaks are occurring.</li><li><strong>Avoid Strong Reference Cycles in Collections:</strong> If collections like arrays or dictionaries hold objects with strong references back to the collection, this can cause memory leaks. It’s essential to manage these relationships carefully.</li><li><strong>Singletons:</strong> Ensure that your singletons do not retain other objects unnecessarily. It’s also a good practice to ensure that singletons can be destroyed or that they clean up resources when they are no longer needed.</li><li><strong>Timers:</strong> If a timer holds a strong reference to its target and the target holds a strong reference to the timer, this can create a retain cycle. Ensure you invalidate timers when they’re no longer needed.</li></ol><h3>Best Practices:</h3><ol><li><strong>Regularly Audit Your Code:</strong> Periodically review your code for potential memory issues. Look out for retain cycles, especially in places where objects have relationships with each other.</li><li><strong>Understand ARC:</strong> Automatic Reference Counting (ARC) is a memory management feature of Swift and Objective-C. Having a deep understanding of how ARC works can help developers write leak-free code.</li><li><strong>Prioritise Code Reviews:</strong> Encourage code reviews in your team. Often, a fresh set of eyes can quickly spot potential memory issues.</li><li><strong>Educate Your Team:</strong> Ensure your development team understands the basics of memory management in iOS. Organize workshops or training sessions if necessary.</li></ol><h3>Conclusion:</h3><p>Memory leaks might seem benign at first, but over time they can degrade the user experience. Being proactive in identifying and fixing these leaks is essential for maintaining app performance and ensuring happy users. By understanding the common causes of memory leaks and following best practices, you can keep your iOS apps running smoothly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c44ecf97f99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UserDefaults vs.]]></title>
            <link>https://medium.com/@muradwajed/userdefaults-vs-a0655dd949a2?source=rss-bc0f2f440fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0655dd949a2</guid>
            <category><![CDATA[filesystem]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[storage]]></category>
            <category><![CDATA[keychain]]></category>
            <category><![CDATA[userdefaults]]></category>
            <dc:creator><![CDATA[Murad Al Wajed]]></dc:creator>
            <pubDate>Mon, 21 Aug 2023 04:39:02 GMT</pubDate>
            <atom:updated>2023-08-21T04:39:02.260Z</atom:updated>
            <content:encoded><![CDATA[<h3>UserDefaults vs. Keychain vs. File System: Choosing the Right Data Storage Solution in iOS Development</h3><p>In iOS development, managing data effectively is crucial for building efficient, secure, and user-friendly applications. Different scenarios call for different data storage solutions, and three commonly used options are UserDefaults, the Keychain, and the file system. In this article, we&#39;ll explore the differences between these three storage solutions to help you make informed decisions based on your application&#39;s requirements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mcYkCagVuGgFKc3OD5qmzw.png" /></figure><h3>UserDefaults: Simple and Lightweight</h3><p>UserDefaults is the go-to solution for storing small amounts of data, primarily user preferences and application settings. It provides a lightweight and straightforward interface for storing and retrieving key-value pairs.</p><h4>Advantages of UserDefaults:</h4><ol><li><strong>Simplicity:</strong> UserDefaults offers an easy-to-use API, making it suitable for managing simple app settings and preferences.</li><li><strong>Persistence:</strong> Data stored in UserDefaults persists across app launches and is automatically synchronized across devices using iCloud if configured.</li><li><strong>Non-Sensitive Data:</strong> It’s appropriate for storing non-sensitive data, such as UI state, user interface preferences, and lightweight configurations.</li></ol><h4>Considerations:</h4><ol><li><strong>Data Size:</strong> UserDefaults is not designed for storing large amounts of data. It&#39;s best suited for small pieces of information.</li><li><strong>Security:</strong> While data in UserDefaults is accessible to anyone with access to the device, it is not suitable for storing sensitive information due to its lack of encryption.</li></ol><h3>Keychain: Security and Sensitive Data</h3><p>The Keychain is the solution of choice for storing sensitive data securely. It&#39;s designed to hold cryptographic keys, passwords, authentication tokens, and other confidential information. It can be keep data save even if user uninstall the app.</p><h4>Advantages of Keychain:</h4><ol><li><strong>Security:</strong> The Keychain provides strong encryption and access controls, making it the ideal choice for storing sensitive data.</li><li><strong>Persistence:</strong> Data stored in the Keychain persists across app launches and offers protection against data loss, similar to UserDefaults.</li><li><strong>Access Control:</strong> You can define specific access controls for items in the Keychain, giving you control over who can access or modify the data.</li></ol><h4>Considerations:</h4><ol><li><strong>Complexity:</strong> Working with the Keychain can be more complex due to its advanced security features. Properly managing access controls and keys is essential.</li><li><strong>Performance:</strong> While secure, accessing data from the Keychain might have slightly more overhead compared to other solutions.</li></ol><h3>File System: Versatility and Customisation</h3><p>For more complex data storage needs, such as large files or structured data, using the file system can provide flexibility and customisation.</p><h3>Advantages of File System:</h3><ol><li><strong>Versatility:</strong> The file system allows you to store various types of data, from images and videos to custom data files and databases.</li><li><strong>Customisation:</strong> You have full control over how data is organized and stored, allowing you to optimise performance for specific use cases.</li><li><strong>Large Data:</strong> The file system is suitable for handling larger data sets that may not fit well within the constraints of UserDefaults or the Keychain.</li></ol><h3>Considerations:</h3><ol><li><strong>Security:</strong> While you can implement your own security measures, managing security on the file system requires more effort compared to the built-in security features of UserDefaults and the Keychain.</li><li><strong>Complexity:</strong> Working with the file system requires careful consideration of file paths, error handling, and proper management of file resources.</li></ol><h3>Choosing the Right Solution</h3><p>To choose the appropriate storage solution, consider the nature of the data you’re dealing with:</p><ul><li>Use UserDefaults for simple app preferences and settings that are non-sensitive and can be easily managed.</li><li>Use the Keychain for storing sensitive data such as passwords, authentication tokens, and cryptographic keys that require strong security and access controls.</li><li>Use the File System for handling larger files, structured data, and custom data storage requirements, where versatility and customisation are essential.</li></ul><h3>Conclusion</h3><p>Data storage is a fundamental aspect of iOS development, and the choice between UserDefaults, the Keychain, and the file system depends on your application&#39;s specific needs. By understanding the strengths and limitations of each option, you can make informed decisions that ensure the security, efficiency, and functionality of your app. Whether it&#39;s managing user preferences, securing sensitive information, or handling complex data structures, the right storage solution will contribute to a seamless user experience and the overall success of your iOS application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0655dd949a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Autoreleasepool in iOS Development: Managing Memory Efficiently]]></title>
            <link>https://medium.com/@muradwajed/autoreleasepool-in-ios-development-managing-memory-efficiently-a1821f6589ae?source=rss-bc0f2f440fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1821f6589ae</guid>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[objective-c]]></category>
            <dc:creator><![CDATA[Murad Al Wajed]]></dc:creator>
            <pubDate>Sat, 19 Aug 2023 02:58:36 GMT</pubDate>
            <atom:updated>2023-08-19T02:58:36.811Z</atom:updated>
            <content:encoded><![CDATA[<p>Memory management is a critical aspect of software development, especially in resource-constrained environments like mobile devices. In iOS development, Apple provides developers with a robust memory management system that helps prevent memory leaks and ensure efficient use of resources. One key component of this system is the @autoreleasepool construct, which plays a crucial role in managing memory within your iOS applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a1B8xSGjCgbxuMIUo_59ag.png" /></figure><h3>What is Autoreleasepool?</h3><p>In iOS development, an autorelease pool is a mechanism used to manage the lifecycle of objects created with the “autorelease” mechanism. The autorelease mechanism is designed to simplify memory management by allowing objects to be released automatically at a later time, rather than requiring developers to explicitly manage memory deallocation.</p><p>When you create an object in Objective-C or Swift and mark it for autorelease, it is added to the nearest autorelease pool. The autorelease pool keeps track of these objects and releases them when the pool is drained. This process helps developers avoid the manual memory management overhead that comes with explicitly releasing objects when they’re no longer needed.</p><h3>How Autoreleasepool Works</h3><p>Consider a scenario where you’re iterating through a loop and creating a large number of temporary objects inside it. Without autorelease pools, these objects would accumulate in memory until the loop is completed, potentially causing memory issues. Autorelease pools solve this problem by allowing you to group the creation and disposal of objects within a specific scope.</p><p>Here’s a simplified example in Objective-C and Swift:</p><pre>for (int i = 0; i &lt; 1000; i++) {<br>    @autoreleasepool {<br>        // Create and use temporary objects<br>        NSString *tempString = [NSString stringWithFormat:@&quot;Temporary Object %d&quot;, i];<br>        // ... (perform operations using tempString)<br>    }<br>}</pre><pre>for i in 0..&lt;1000 {<br>    autoreleasepool {<br>        // Create and use temporary objects<br>        let tempString = &quot;Temporary Object \(i)&quot;<br>        // ... (perform operations using tempString)<br>    }<br>}</pre><p>In this example, an autorelease pool is created within the loop. As the loop iterates, the temporary objects created within each iteration are added to the pool. Once the pool is drained (when the closing brace of the @autoreleasepool block is reached), all the temporary objects are released from memory.</p><h3>Use Cases for Autoreleasepool</h3><p>Autorelease pools are particularly useful in scenarios where you’re creating a large number of short-lived objects. Some common use cases include:</p><ol><li><strong>Loop Iterations: </strong>As shown in the example above, when you’re performing repetitive operations in a loop and generating temporary objects within each iteration.</li><li><strong>Parsing Data: </strong>When parsing data from sources like JSON or XML, temporary objects may be created while processing each element.</li><li><strong>Multithreading:</strong> In multithreaded environments, each thread should have its own autorelease pool to ensure proper memory management.</li><li><strong>Event Handling: </strong>Autorelease pools can be used in event-driven scenarios where you’re processing a series of events that generate temporary objects.</li></ol><h3>Modern Memory Management and Swift</h3><p><strong>While autorelease pools have been a vital part of memory management in Objective-C, Swift introduced Automatic Reference Counting (ARC), a more advanced memory management system.</strong> ARC automatically manages the memory of objects by keeping track of references to them and releasing them when they’re no longer needed.</p><p>In Swift, you don’t usually need to work directly with autorelease pools, as ARC handles memory management for you. <strong>However, there might still be situations where you’re interacting with Objective-C code or need to manage memory explicitly, and in those cases, you can utilise autorelease pools.</strong></p><h3>Conclusion</h3><p>Autorelease pools are a powerful tool for managing memory in iOS development, particularly in situations involving the creation of a large number of short-lived objects. While modern memory management systems like ARC handle memory automatically in Swift, understanding how autorelease pools work can be beneficial when interacting with Objective-C code or working in specific scenarios.</p><p>By effectively using autorelease pools, you can ensure that your iOS applications maintain efficient memory usage, prevent memory leaks, and provide a smooth user experience, even in resource-intensive scenarios. Remember that while autorelease pools are a valuable tool, they should be used judiciously and only when needed to optimize memory management without introducing unnecessary complexity to your codebase.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1821f6589ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>