当前位置: 代码网 > it编程>开发工具>IDE > 轻量级的VsCode为何越用越大?为什么吃了我C盘10G?如何无痛清理VsCode缓存?手把手教你为C盘瘦身

轻量级的VsCode为何越用越大?为什么吃了我C盘10G?如何无痛清理VsCode缓存?手把手教你为C盘瘦身

2024年08月01日 IDE 我要评论
轻量级的VsCode为何越用越大?为什么吃了我C盘10G?如何无痛清理VsCode缓存?手把手教你为C盘瘦身VsCode缓存清理清理VsCode缓存清除VsCode缓存解放你的双手,定期自动清理空间

vscode是一款轻量级代码编辑器

可用一段就会很快发现,“轻量级”的vscode并不轻量

不统计不知道,一统计吓一跳,使用了一段时间后,vscode占用了我c盘10g+的空间!

好家伙,于是我决定治理一下vscode,让vscode变得真正的轻量级。

vscode的空间占用分析

vscode所占用的空间,主要包括四大部分(下面是我写此博客时统计的结果):

  1. 程序的安装目录:大约会占用350m
  2. %userprofile%\.vscode:可达800m。主要为:各个拓展。vscode卸载拓展似乎不会删除硬盘上的文件,因此这个里面很大,并且混有很多不用的
  3. %userprofile%\appdata\local\microsoft\vscode-cpptools\ipch :用一段时间能达到4g 与c(++)语言有关,关闭程序后可以直接删。不使用vscode编辑c/c++的用户可能无此痛苦
  4. %userprofile%\appdata\roaming\code:2g+ 存放用户数据、配置等。 (可以通过启动时添加–user-data-dir newdir 来使其他目录作为配置)

可以定期删除的地方,有3. ipch(可完全删除) 和 4. romaing(不可完全删除)

4. romaing中,到底哪些可以定期删除

%userprofile%\appdata\roaming\code中的文件进行更进一步地分析,我得到了如下结论:

%userprofile%\appdata\roaming\code\cachedextensionvsixs   用一段时间可以达到500m   可以直接删
%userprofile%\appdata\roaming\code\cache       很快几十m
%userprofile%\appdata\roaming\code\cacheddata  很快几十m
%userprofile%\appdata\roaming\code\cachedextensions  安装新插件时,似乎默认不会自动删除,安装插件一多能达到800m
%userprofile%\appdata\roaming\code\cachedextensionvsixs 反正也是与插件有关的,也能达到几百m
%userprofile%\appdata\roaming\code\code cache    十几m
%userprofile%\appdata\roaming\code\crashpad      十几m  用来存放崩溃信息
%userprofile%\appdata\roaming\code\logs          几十m  这个可以直接删,用来存放日志记录
%userprofile%\appdata\roaming\code\service worker 1g    
    %userprofile%\appdata\roaming\code\service worker\cachestorage   1g  主要位于这里
    %userprofile%\appdata\roaming\code\service worker\scriptcache    10m
%userprofile%\appdata\roaming\code\user          600m
    %userprofile%\appdata\roaming\code\user\workspacestorage  500m  每打开一个工作目录就会在这个目录下生成一个文件夹
    %userprofile%\appdata\roaming\code\user\history           100m
            每ctrl+s(仅限有修改的成功的重新保存)一次就会生成一个副本。
            这个不是按git的思路只存放更改,而是整个文件全部copy一份。
            一个100多k的源码保存十次就是1m,对于习惯随手ctrl+s的用户会占用较大的空间
            但是,删除之后将会影响历史版本的还原。
            其中,文件名采用了代码混淆技术,每个文件会生成一个文件夹,真正的文件名、各个文件对应文件保存时间都在每个文件夹下的entries.json中
    %userprofile%\appdata\roaming\code\user\snippets    这个不能删,并且重装还得记得备份(如果没有自动还原的话)这个是用户自定义的代码片段

能定时删除的目录

  1. %userprofile%\appdata\local\microsoft\vscode-cpptools\ipch
  2. %userprofile%\appdata\roaming\code\cachedextensionvsixs
  3. %userprofile%\appdata\roaming\code\cache
  4. %userprofile%\appdata\roaming\code\cacheddata
  5. %userprofile%\appdata\roaming\code\cachedextensions
  6. %userprofile%\appdata\roaming\code\cachedextensionvsixs
  7. %userprofile%\appdata\roaming\code\code cache
  8. %userprofile%\appdata\roaming\code\crashpad
  9. %userprofile%\appdata\roaming\code\logs
  10. %userprofile%\appdata\roaming\code\service worker\cachestorage
  11. %userprofile%\appdata\roaming\code\service worker\scriptcache
  12. %userprofile%\appdata\roaming\code\user\workspacestorage
  13. %userprofile%\appdata\roaming\code\user\history

这么多文件夹总不可能手动地一个一个地删除,因此我写了一个脚本:

@rem example:
@rem del "%userprofile%/appdata/local/microsoft/vscode-cpptools/ipch/" /s /q /f
@rem rd "%userprofile%/appdata/local/microsoft/vscode-cpptools/ipch/" /s /q
@rem md "%userprofile%/appdata/local/microsoft/vscode-cpptools/ipch/"

@echo off

call:emptyonedir "%userprofile%\appdata\local\microsoft\vscode-cpptools\ipch"
call:emptyonedir "%userprofile%\appdata\roaming\code\cachedextensionvsixs"
call:emptyonedir "%userprofile%\appdata\roaming\code\cache"
call:emptyonedir "%userprofile%\appdata\roaming\code\cacheddata"
call:emptyonedir "%userprofile%\appdata\roaming\code\cachedextensions"
call:emptyonedir "%userprofile%\appdata\roaming\code\cachedextensionvsixs"
call:emptyonedir "%userprofile%\appdata\roaming\code\code cache"
call:emptyonedir "%userprofile%\appdata\roaming\code\crashpad"
call:emptyonedir "%userprofile%\appdata\roaming\code\logs"
call:emptyonedir "%userprofile%\appdata\roaming\code\service worker\cachestorage"
call:emptyonedir "%userprofile%\appdata\roaming\code\service worker\scriptcache"
call:emptyonedir "%userprofile%\appdata\roaming\code\user\workspacestorage"
call:emptyonedir "%userprofile%\appdata\roaming\code\user\history"

goto end

:emptyonedir  rem same as let empty [path] /q
    echo empty %1
    echo del %1 /s /q /f
    del %1 /s /q /f
    echo rd %1 /s /q
    rd %1 /s /q
    echo md %1
    md %1
:end

只需要将这个脚本另存为cleanvscode.bat,并定期双击运行一次,就能定期释放大量空间

当然,释放的空间直接取决于你的vscode所产生的缓存大小,间接取决于你的vscode的使用次数。

最好关闭vscode后再运行脚本。

⚠️warning

运行脚本后再次运行vscode基本上看不出什么不同,只是当前工作路径下所打开的文件需要重新手动点击打开。

毕竟是一个能删除很多东西的脚本,因此请谨慎使用。

我作为本篇博客的原创博主,只是为大家提供了一个便捷的方法,但是其可能造成的后果,博主并不承担责任。

但是大家可以放心的是,我自己也在定期运行这个脚本。

准备有空的时候将其加入windows计划,以实现定期地自动释放空间。

视频版演示:

轻量级的vscode为何越用越大?为什么吃了我c盘10g?如何无痛清理vscode缓存?手把手教你为c盘瘦身

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com