Required information in an Excessive Memory Use Bug
1. Memory use numbers
Please provide numbers for the memory use you observe.
- On Mac
- Run "Activity Monitor", and record the "RPRVT" number. (You may have to enable this column manually by right-clicking on the column headers and selecting "Private Memory".)
- On Windows
- Run "Task Manager", and record the "Private Working Set" number. (You may have to enable this column manually. See http://cybernetnews.com/2007/11/20/cybernotes-windows-memory-usage-explained/ .)
2. "Steps to reproduce", including OS version
- Please provide an exact set of steps that an engineer can follow in order to reproduce the numbers you report, starting with, "Launch Safari."
- The steps should show that memory use goes up without coming back down.
- The steps should employ a fixed set of web content. (It's normal for memory use to go up as you load more and more content—that's a result of caching.)
- If possible, provide a reduced test case that includes just the portions of web content necessary to reproduce the behavior you report, and not any surrounding or related content. This will make debugging the issue much easier.
Examples of good Excessive Memory Use Bugs
Below are some examples of good memory use bugs.
"Memory use goes up by 500KB every time I reload gmail.com"
OS: Windows XP SP2. Steps to reproduce: 1. Launch Safari 2. Load gmail.com. Memory use: 15MB 3. Click the "reload" button. Memory use: 15.5MB 4. Click the "reload" button. Memory use: 16.0MB After 10 reloads, memory reaches 20.0MB.
"Safari uses 20MB more memory than IE7 when loading a specific set of websites in tabs"
OS: Mac OS X 10.5.2. Steps to reproduce: 1. Launch Safari and IE7. Safari's memory use: 16MB. IE7's memory use: 16MB. 2. Load the following URLs in tabs: cnn.com, apple.com, nytimes.com, slashdot.org, digg.com Safari memory use: 38MB IE7's memory use: 18MB.
"Memory use grows by 165KB every time I load a 165KB file by XMLHttpRequest"
OS: Mac OS X 10.4.3. Steps to reproduce: 1. Launch Safari. 2. Load the attached reduced test case. Memory use: 17MB. 3. Click the "make an XMLHttpRequest" button. Memory use: 17.165MB. 4. Click the "make an XMLHttpRequest" button. Memory use: 17.330MB. After 10 clicks, memory use reaches 18.65MB.
Tools for Diagnosing an Excessive Memory Use Bug
Use a debug build of WebKit. It will give you more diagnostic information.
- On Mac
-
Launch Safari from the terminal:
Tools/Scripts/run-safari --debug
- On Windows
-
Launch Safari from the cygwin terminal, with standard output enabled:
Tools/Scripts/run-safari --debug 2>&1 | cat
Having reproduced the bug, follow these steps in order to diagnose common memory use culprits:
1. Close all windows
- On Mac
- Open a dummy empty window. Close all other windows. (Closing all windows would quit Safari.)
- On Windows
- Close all windows.
Record whether the memory use number returned to normal.
- On Mac
- Record whether you saw a "World Leak" dialog.
- On Windows
- Using the debugger, open a watch window for WebViewCount, WebFrameViewCount, and WebFrameCount. Each count should be 1 (representing your empty window). For a broader perspective, you can also watch gClassCount, which counts all classes in the WebKit API.
2. Check the JavaScript object footprint
- Select Debug ▶ Show Caches Window.
- Click the "Garbage Collect JavaScript Objects" button.
- Record whether the memory use number returned to normal.
- Record whether the "Total Objects", "Global Objects", and "Protected Objects" counts in the "JavaScript Objects" box returned to 0.
3. Check the cache footprint
- Select Debug ▶ Show Caches Window.
- Click the "Empty WebCore Cache" button. Record whether the memory use number returned to normal.
- Click the "Empty NSURLCache" button. Record whether the memory use number returned to normal.
- Click the "Purge Inactive Font Data" button. Record whether the memory use number returned to normal.
4. Check for leaks (I)
- Quit the application.
- Record any "LEAK: " messages you see in the terminal.
- NOTE: This step will yield false positives until we fix the fast teardown / GC bug.
4.1 Check for leaks (II - Mac only)
- Relaunch Safari with malloc logging enabled:
MallocStackLogging=1 ./Safari.app/Contents/MacOS/Safari
. - After reproducing the bug, run the
leaks
command-line tool, and record the "Process X: Y leaks for Z total leaked bytes" line, along with backtraces from substantial leaks.
5. Try the hard stuff
The steps above cover common causes of memory use. If none of them reveals the culprit, you'll need to dig deeper.
- On Mac
-
Use
malloc_history
to track down who's using memory and why. - On Windows
-
Use
umdh.exe
to track down who's using memory and why.
You can Google for more information about these tools. We hope to have detailed instructions for using them, along with helper tools, soon.