
Git bash (sh.exe) 佔用的記憶體很少,但當使用 CMDstart sh.exe
命令啟動時,它會建立一個佔用 3-700 MB 記憶體的 conhost.exe 進程。
有趣的是,start cmd /k sh.exe
它做了同樣的事情,但它創建的 conhost 進程只需要 8 MB。
為什麼使用「start」指令啟動 sh.exe 會建立一個佔用更多記憶體的 conhost 進程?
答案1
好的,我都看了使用 WPA.exe 進行追蹤。在顯示高記憶體使用率的追蹤中,記憶體使用量來自建立螢幕緩衝區DoCreateScreenBuffer
:
Line #, Process, Commit Stack, Address, Count, Impacting Size, Size
1, conhost.exe (10848), [Root], , 46, 800784384, 800833536
2, , |- ntdll.dll!RtlUserThreadStart, , 31, 800669696, 800673792
3, , | kernel32.dll!BaseThreadInitThunk, , 31, 800669696, 800673792
4, , | |- ConhostV2.dll!ConsoleIoThread, , 13, 800509952, 800509952
5, , | | ConhostV2.dll!ConsoleHandleConnectionRequest, , 13, 800509952, 800509952
6, , | | ConhostV2.dll!ConsoleAllocateConsole, , 13, 800509952, 800509952
7, , | | |- ConhostV2.dll!SetUpConsole, , 10, 800460800, 800460800
8, , | | | |- ConhostV2.dll!AllocateConsole, , 7, 800432128, 800432128
9, , | | | | ConhostV2.dll!DoCreateScreenBuffer, , 7, 800432128, 800432128
10, , | | | | |- ConhostV2.dll!SCREEN_INFORMATION::CreateInstance, , 6, 800415744, 800415744
11, , | | | | | ConhostV2.dll!TEXT_BUFFER_INFO::CreateInstance, , 6, 800415744, 800415744
12, , | | | | | |- ConhostV2.dll!DBCS_SCREEN_BUFFER::CreateInstance, , 4, 599891968, 599891968
13, , | | | | | | ntdll.dll!RtlpAllocateHeapInternal, , 4, 599891968, 599891968
14, , | | | | | | ntdll.dll!RtlpAllocateHeap, , 4, 599891968, 599891968
15, , | | | | | | ntdll.dll!NtAllocateVirtualMemory, , 4, 599891968, 599891968
16, , | | | | | | ntoskrnl.exe!KiSystemServiceCopyEnd, , 4, 599891968, 599891968
17, , | | | | | | ntoskrnl.exe!NtAllocateVirtualMemory, , 4, 599891968, 599891968
18, , | | | | | | ntoskrnl.exe! ?? ::NNGAKEGL::`string', , 4, 599891968, 599891968
一是start cmd /k sh.exe
不進行記憶體分配。這裡只印了一些字符,只使用了 69kB。
Line #, Process, Commit Stack, Address, Count, Impacting Size, Size
7, conhost.exe (10072), [Root], , 2, 81920, 81920
8, , ntdll.dll!RtlUserThreadStart, , 2, 81920, 81920
9, , kernel32.dll!BaseThreadInitThunk, , 2, 81920, 81920
10, , |- ConhostV2.dll!ConsoleIoThread, , 1, 69632, 69632
11, , | ConhostV2.dll!SrvWriteConsole, , 1, 69632, 69632
12, , | ConhostV2.dll!DoSrvWriteConsole, , 1, 69632, 69632
13, , | ConhostV2.dll!DoWriteConsole, , 1, 69632, 69632
14, , | ConhostV2.dll!WriteChars, , 1, 69632, 69632
15, , | ConhostV2.dll!WriteCharsLegacy, , 1, 69632, 69632
16, , | ConhostV2.dll!WriteRegionToScreen, , 1, 69632, 69632
17, , | ConhostV2.dll!ConsolePolyTextOut, , 1, 69632, 69632
18, , | ntdll.dll!RtlpAllocateHeapInternal, , 1, 69632, 69632
19, , | ntdll.dll!RtlpAllocateHeap, , 1, 69632, 69632
20, , | ntdll.dll!RtlpCommitBlock, , 1, 69632, 69632
21, , | ntdll.dll!NtAllocateVirtualMemory, , 1, 69632, 69632
22, , | ntoskrnl.exe!KiSystemServiceCopyEnd, , 1, 69632, 69632
23, , | ntoskrnl.exe!NtAllocateVirtualMemory, , 1, 69632, 69632
24, , | ntoskrnl.exe! ?? ::NNGAKEGL::`string', , 1, 69632, 69632
25, , | , 0x2a657431000, 1, 69632, 69632
但我不知道為什麼會發生這種情況。始終使用 start cmd /k 運行它。