220-1102Chapter 87 of 131Objective 3.1

Troubleshoot: Memory Leak Issues

This chapter covers memory leak issues, a critical topic for the CompTIA A+ Core 2 (220-1102) exam under Domain 3.0: Software Troubleshooting, specifically Objective 3.1: Given a scenario, troubleshoot common Windows, macOS, and Linux issues. Memory leaks are a frequent cause of performance degradation and system instability, and exam questions often test your ability to identify symptoms, use diagnostic tools, and apply corrective actions. Approximately 5-10% of troubleshooting questions touch on memory-related issues, including leaks.

25 min read
Intermediate
Updated May 31, 2026

The Leaky Bucket: Memory Leak Analogy

Imagine a water dispenser with a bucket that fills cups for guests at a party. The bucket has a fixed capacity, say 100 cups. When a guest requests water, the dispenser fills a cup and hands it over. However, a design flaw causes the dispenser to not fully release the cup after serving – it holds onto a small amount of water in the cup, which evaporates but the cup remains in the bucket. Over time, more and more cups accumulate, each holding a tiny residual amount, until the bucket overflows. In a computer, memory is like that bucket. A memory leak occurs when an application allocates memory (e.g., for a data structure) but fails to release it after use. Each allocation is like a cup; the application holds onto it even after it's no longer needed. Over time, available memory shrinks, leading to performance degradation and eventual system instability. The operating system's task manager is like a gauge showing the water level – you can see memory usage climbing steadily. Just as you'd need to identify which guest's cups are being retained, you must find the faulty process. Tools like Resource Monitor or Performance Monitor help pinpoint the leak by tracking memory allocations per process. The solution is to fix the code or, temporarily, restart the application to empty the bucket.

How It Actually Works

What is a Memory Leak?

A memory leak occurs when a computer program incorrectly manages memory allocations such that memory that is no longer needed is not released. In systems programming, memory is allocated dynamically using functions like malloc() in C or new in C++, and it must be freed using free() or delete. In managed languages like Java or C#, the garbage collector automatically reclaims memory, but leaks can still happen if references to objects are inadvertently held (e.g., in static collections). The result is that over time, the program consumes more and more memory, reducing available memory for other programs and the operating system.

How Memory Leaks Work Internally

In a typical scenario, a process requests memory from the operating system via system calls such as VirtualAlloc (Windows) or sbrk/mmap (Linux). The OS allocates pages of physical memory and maps them into the process's virtual address space. Each allocation is tracked in a heap structure managed by the language runtime or the program itself. When the program forgets to deallocate, the heap manager still considers that memory as in-use. Over time, the heap grows, and the process's working set increases. The OS may resort to paging to disk (swapping), causing severe performance degradation.

Key Components and Defaults

Heap: The region of memory used for dynamic allocations. In Windows, the default heap size for a process is 1 MB, but it can grow as needed. In Linux, the heap grows via brk()/sbrk().

Virtual Memory: The OS uses a page file (Windows) or swap partition (Linux) to extend physical memory. Default page file size in Windows is 1.5 times the amount of RAM, but this varies.

Memory Limits: On 32-bit systems, a process can address up to 4 GB of virtual memory (2 GB user space by default). On 64-bit systems, limits are much larger (e.g., 8 TB on Windows 64-bit).

Garbage Collection (GC): In .NET and Java, GC runs periodically to reclaim memory. However, if objects are still referenced (e.g., in event handlers or static lists), they are not collected. The GC uses generational collection: Gen 0 (short-lived), Gen 1, Gen 2 (long-lived). Objects that survive multiple collections get promoted.

Verification and Diagnostic Commands

Windows: - Task Manager: Shows memory usage per process (Working Set, Private Working Set, Commit Size). - Resource Monitor: Provides detailed memory graph and per-process handle counts. - Performance Monitor: Can track counters like Memory\Available Bytes, Process\Private Bytes, and Process\Working Set. - Windows Performance Toolkit (WPT): For deep analysis, use xperf or Windows Performance Recorder (WPR) and Windows Performance Analyzer (WPA). - Debug Diagnostic Tool (DebugDiag): Analyzes memory dumps. - Command line: tasklist /m lists modules; wmic process get name, workingsetsize shows working set sizes.

Linux: - `top` / `htop`: Shows memory usage per process (RES = resident memory, VIRT = virtual memory). - `free -m`: Displays total, used, and free memory, including buffers/cache. - `ps aux --sort=-%mem`: Lists processes sorted by memory usage. - `pmap -x <PID>`: Shows detailed memory map for a process. - `valgrind --leak-check=yes`: For debugging memory leaks in compiled programs. - `/proc/meminfo`: Contains system memory information. - `smem`: Reports memory consumption with shared memory accounting.

macOS: - Activity Monitor: Shows memory pressure, memory usage per process. - `top`: Similar to Linux. - `vmmap <PID>`: Displays virtual memory regions. - `leaks <PID>`: Reports leaked memory for a process (requires developer tools). - `heap <PID>`: Shows heap usage.

How Memory Leaks Interact with System Performance

As a memory leak progresses, available physical memory decreases. The OS begins to page out less frequently used memory to the page file or swap. This causes increased disk I/O, leading to system slowdowns. If memory runs out entirely, the OS may terminate processes (Out-of-Memory killer on Linux) or crash (Windows BSOD with error code 0x0000001A – MEMORY_MANAGEMENT). In virtualized environments, a memory leak in a VM can trigger host-level ballooning or swapping.

Common Causes of Memory Leaks

Unreleased allocations: In C/C++, forgetting to call free() or delete after malloc() or new.

Circular references: In reference-counting systems (e.g., COM, Python), objects that reference each other may never be freed.

Event handlers: In .NET or JavaScript, attaching event handlers without detaching them prevents garbage collection of the subscriber object.

Static collections: Adding objects to a static list without removal keeps them alive forever.

Thread local storage: Allocating memory in thread local storage without cleanup on thread exit.

Handle leaks: Opening files, registry keys, or network connections without closing them (these also consume memory).

Detection and Resolution Steps

1.

Identify the leaking process: Use Task Manager (Windows) or top (Linux) to find a process whose memory usage increases over time.

2.

Gather detailed data: Use Resource Monitor or Performance Monitor to track private bytes and working set over time.

3.

Analyze with specialized tools: For Windows, use DebugDiag or WPA. For Linux, use Valgrind or gdb with heap analysis.

4.

Apply temporary fix: Restart the process or service to reclaim memory. For critical systems, schedule a restart.

5.

Permanent fix: Update the software or apply a patch from the vendor. If in-house, fix the code.

Exam Relevance

The 220-1102 exam expects you to recognize symptoms of memory leaks: gradual performance degradation, system responsiveness loss, and eventual crashes. You should know how to use built-in OS tools to monitor memory usage and identify the offending process. You should also understand that restarting the application or service is a common temporary solution, while updating or patching is the permanent fix. The exam may present scenarios with multiple-choice answers that include options like 'increase virtual memory' or 'add more RAM' – these are incorrect because they treat the symptom, not the cause.

Walk-Through

1

Identify the Symptoms

The first step is to recognize the signs of a memory leak. Common symptoms include: system performance gradually degrading over hours or days, applications becoming sluggish or unresponsive, disk activity increasing due to swapping, and eventually out-of-memory errors or system crashes. On Windows, you might see error messages like 'Your system is low on virtual memory' or a blue screen with error code 0x0000001A (MEMORY_MANAGEMENT). On Linux, the OOM killer may terminate processes, logged in `/var/log/messages`. The key is that these symptoms worsen over time without any other changes, such as new software installations.

2

Open Task Manager or Monitor

On Windows, press Ctrl+Shift+Esc to open Task Manager. Click the 'Processes' tab and add the 'Memory' column (if not visible) by right-clicking column headers. Sort by memory usage to see which processes consume the most memory. On Linux, use `top` or `htop`. Look for a process whose memory usage (RES column) steadily increases. On macOS, use Activity Monitor and sort by 'Memory'. Note the baseline memory usage and observe over several minutes to see if it climbs without bound. A normal process may have fluctuations, but a leak will show a consistent upward trend.

3

Use Resource Monitor for Detail

For deeper analysis on Windows, open Resource Monitor (resmon.exe). Go to the 'Memory' tab. Here you can see a graph of memory usage over time. In the 'Processes' section, you can view 'Private Bytes' and 'Working Set' for each process. Private Bytes indicate memory allocated specifically for that process and cannot be shared. A steady increase in Private Bytes is a strong indicator of a memory leak. Also check the 'Hard Faults/sec' column – an increase suggests the system is paging excessively due to memory pressure. On Linux, use `vmstat 5` to watch swapping activity.

4

Track Memory Over Time

To confirm a leak, you need to observe memory usage over an extended period. On Windows, you can use Performance Monitor (perfmon.exe) to create a data collector set that logs the `Process\Private Bytes` counter for suspicious processes. On Linux, you can write a script that captures `ps aux` output every minute and logs it. Look for a linear or exponential increase. For example, if a process starts at 100 MB and grows to 500 MB over 4 hours, it's likely leaking. Compare with other instances of the same application to rule out normal behavior.

5

Apply Temporary Fix and Permanent Solution

The immediate fix is to stop and restart the leaking process or service. On Windows, you can right-click the process in Task Manager and select 'End Task', or use `taskkill /F /PID <pid>`. For a service, use `net stop <service>` then `net start <service>`. On Linux, use `kill -9 <pid>`. This frees all memory allocated by the process. For a permanent solution, check for updates from the software vendor. If it's custom software, developers should use debugging tools like Valgrind (Linux) or Application Verifier (Windows) to find the leak in the code. Alternatively, increase monitoring to schedule automatic restarts during low-usage periods.

What This Looks Like on the Job

In a large enterprise environment, a memory leak can have significant impact. Consider a company running a critical web application on a Windows Server 2019 machine with 64 GB of RAM. The application, a custom .NET web service, gradually consumes memory over days. Initially, it uses 2 GB, but after a week, it reaches 30 GB, causing the server to page heavily. The system becomes unresponsive, and the application pool crashes. The IT team uses Performance Monitor to track the Process\Private Bytes counter for the w3wp.exe process. They see a steady increase of about 500 MB per day. They temporarily resolve the issue by configuring IIS to recycle the application pool daily at 3 AM. The permanent fix is to update the application code after a developer uses WinDbg to analyze a memory dump and finds that static event handlers are preventing garbage collection of cached objects.

Another scenario: A Linux server running a Java-based application (e.g., Apache Tomcat) experiences memory leaks. The Java heap grows until the OutOfMemoryError occurs. The admin uses jmap -heap <pid> to see heap usage and jvisualvm to analyze the heap dump. They discover that a HashMap used to cache session data never removes expired sessions. The fix is to implement a proper eviction policy or use a caching library like Ehcache.

A third example: A macOS system running a third-party graphics application gradually slows down. The user notices that the application's memory usage in Activity Monitor climbs from 500 MB to 4 GB over a few hours. They force quit the app and relaunch it. The vendor later releases an update that fixes a memory leak in the rendering engine. The lesson: always check for software updates. In all these cases, the key is early detection through monitoring, immediate mitigation via restart, and long-term resolution by patching or code fixes.

How 220-1102 Actually Tests This

The 220-1102 exam tests memory leaks under Objective 3.1: 'Given a scenario, troubleshoot common Windows, macOS, and Linux issues.' You must be able to identify the symptoms, use built-in tools, and apply appropriate fixes. Common exam questions present a scenario where a user reports that a computer has become slow over time, and you must select the correct troubleshooting step. The most common wrong answers include:

1.

'Increase the page file size' – This is wrong because it only masks the symptom by providing more virtual memory, but the leaking process will eventually consume that too, and performance will still degrade due to excessive paging.

2.

'Add more RAM' – Similarly, this treats the symptom, not the cause. The leak will continue to consume memory until the new RAM is exhausted.

3.

'Run a disk cleanup' – This addresses disk space, not memory. Memory leaks are about RAM, not hard drive capacity.

4.

'Disable startup programs' – This reduces initial memory usage but does not fix a leak that occurs after the program runs.

The correct approach is to identify the process consuming memory using Task Manager or Resource Monitor, then restart the process or service. The exam may also ask about the best permanent solution: 'Update the software or apply a patch.'

Specific values to remember: On Windows, the Memory\Available Bytes counter in Performance Monitor indicates free memory; a value consistently below 10% of total RAM suggests memory pressure. The Process\Private Bytes counter is the best indicator of a memory leak. On Linux, the RES column in top shows resident memory; a steady increase indicates a leak. The exam may also reference the vmmap tool on macOS.

Edge cases: The exam might describe a scenario where memory usage spikes after a specific action (e.g., opening a file) and never drops. That is a classic leak. Also, be aware that some leaks are very slow, so monitoring for hours may be necessary. The exam expects you to know that restarting the application is the immediate fix, but the permanent fix is to update or patch the software.

Key Takeaways

A memory leak is the failure to release memory that is no longer needed, causing available memory to shrink over time.

Common symptoms: gradual system slowdown, increased disk activity (swapping), and eventual out-of-memory errors or crashes.

On Windows, use Task Manager and Resource Monitor to identify the leaking process by tracking Private Bytes.

On Linux, use `top` or `ps` to see resident memory (RES) growth; use Valgrind for code-level debugging.

On macOS, use Activity Monitor and the `leaks` command-line tool.

The immediate fix is to restart the leaking process or service.

The permanent fix is to update the software or apply a vendor patch.

Do not increase page file size or add RAM as a solution – these treat symptoms, not the cause.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Memory Leak

Caused by failure to release allocated memory.

Results in steadily increasing memory usage over time.

Symptoms: gradual slowdown, eventual out-of-memory errors.

Diagnosed by monitoring private bytes or heap size growth.

Fix: restart process or patch software.

Memory Fragmentation

Caused by many small allocations and deallocations creating non-contiguous free blocks.

Memory usage may not increase, but allocation failures occur due to lack of contiguous space.

Symptoms: allocation failures even when total free memory is sufficient.

Diagnosed by analyzing heap fragmentation via tools like VMMap.

Fix: use a different memory allocator or defragment heap (e.g., using `malloc_trim` on Linux).

Watch Out for These

Mistake

A memory leak will always cause a blue screen of death (BSOD) immediately.

Correct

Memory leaks typically cause gradual performance degradation over hours or days. A BSOD occurs only when the system runs out of memory completely or encounters a critical memory management error, which is a late-stage symptom.

Mistake

Increasing virtual memory (page file) solves a memory leak.

Correct

Increasing the page file only extends the amount of disk space used as virtual memory. The leaking process will continue to consume memory, eventually exhausting the larger page file as well, and performance will still suffer due to increased paging activity.

Mistake

A memory leak only happens in poorly written code; modern managed languages like Java and C# are immune.

Correct

Even in garbage-collected languages, memory leaks can occur if objects are unintentionally held by references, such as in static collections, event handlers, or caches. The garbage collector cannot reclaim objects that are still reachable.

Mistake

You can fix a memory leak by running a registry cleaner or disk defragmenter.

Correct

Registry cleaners and defragmenters do not affect process memory. They address file system and registry issues, not runtime memory allocation. The proper fix is to identify and restart the leaking process or update the software.

Mistake

If Task Manager shows high memory usage, it must be a memory leak.

Correct

High memory usage can be normal for memory-intensive applications like databases, video editors, or virtual machines. A memory leak is characterized by a steady increase over time without a corresponding increase in workload. Compare baseline usage after a fresh start.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is a memory leak in computing?

A memory leak occurs when a program allocates memory but fails to deallocate it after use. Over time, the program consumes more and more memory, reducing available memory for other processes and the OS. This leads to performance degradation and potential system instability. Memory leaks are common in languages without automatic garbage collection (like C/C++) but can also occur in managed languages if references are inadvertently held.

How do I check for memory leaks in Windows 10?

Open Task Manager (Ctrl+Shift+Esc) and go to the Processes tab. Add the Memory column and sort by it. Look for a process whose memory usage steadily increases. For more detail, use Resource Monitor (resmon.exe) and view the Memory tab. Track the Private Bytes column – a continuous increase indicates a leak. You can also use Performance Monitor to log counters over time.

Can a memory leak cause a blue screen?

Yes, if a memory leak exhausts all available physical and virtual memory, the system may crash with a blue screen error, such as 0x0000001A (MEMORY_MANAGEMENT) or 0x0000000A (IRQL_NOT_LESS_OR_EQUAL). However, most leaks cause gradual slowdown before a crash, giving you time to diagnose and intervene.

What is the difference between a memory leak and a memory fragmentation?

A memory leak is the failure to free allocated memory, causing total memory usage to increase. Memory fragmentation occurs when free memory is broken into small, non-contiguous blocks, making it difficult to satisfy large allocation requests even though total free memory is sufficient. Both can cause allocation failures, but the symptoms and solutions differ.

How do I fix a memory leak in a Java application?

First, identify the leaking process using `jps` or `ps`. Use `jmap -heap <pid>` to see heap usage. Generate a heap dump with `jmap -dump:format=b,file=heap.hprof <pid>` and analyze it with tools like Eclipse MAT or JVisualVM. Look for objects that accumulate, such as entries in a static HashMap. The fix is to modify the code to remove references when no longer needed, or to use a proper caching solution with eviction policies.

Is restarting the computer a permanent fix for a memory leak?

No, restarting the computer or the leaking process is only a temporary fix. It clears the memory and resets the process, but the leak will recur because the underlying software flaw remains. The permanent fix is to update the software to a version that resolves the leak, or to apply a vendor patch. In some cases, you may need to reconfigure the application to limit memory usage.

What tools can I use to detect memory leaks in Linux?

Common tools include `valgrind` with the `--leak-check=yes` option for compiled programs, `heaptrack` (a KDE tool), and `gperftools` for heap profiling. For Java, use `jvisualvm` or `jconsole`. For Python, use `tracemalloc` or `objgraph`. For general monitoring, use `top`, `htop`, `ps`, and `smem` to watch memory usage over time.

Terms Worth Knowing

Ready to put this to the test?

You've just covered Troubleshoot: Memory Leak Issues — now see how well it sticks with free 220-1102 practice questions. Full explanations included, no account needed.

Done with this chapter?