当前位置:网站首页>golang clean a slice
golang clean a slice
2022-06-24 03:34:00 【大魔法师云中君】
To remove all elements, set the slice to nil:
a := []string{
"A", "B", "C", "D", "E"}
a = nil
fmt.Println(a, len(a), cap(a)) // [] 0 0
This will release the underlying array to the garbage collector
(assuming there are no other references).
Keep allocated memory
To keep the underlying array, slice the slice to zero length:
a := []string{
"A", "B", "C", "D", "E"}
a = a[:0]
fmt.Println(a, len(a), cap(a)) // [] 0 5
If the slice is extended again, the original data reappears:
fmt.Println(a[:2]) // [A B]
边栏推荐
- Get to know MySQL database
- Micro build low code enterprise exchange day · Shenzhen station opens registration
- What is elastic scaling in cloud computing? What are the main applications of elastic scaling in cloud computing?
- Which brand is a good backup all-in-one machine price
- ClickHouse Buffer
- web渗透测试----5、暴力破解漏洞--(4)Telnet密码破解
- [see you] on October 24, we met at Tencent Binhai building
- What does cloud desktop mean? What are the characteristics of cloud desktop?
- web渗透测试----5、暴力破解漏洞--(2)SNMP密码破解
- Tencent location service appeared at the 11th China Surveying and mapping Geographic Information Technology Equipment Expo
猜你喜欢

元气森林推“有矿”,农夫山泉们跟着“卷”?

618大促:手机品牌“神仙打架”,高端市场“谁主沉浮”?

在pycharm中pytorch的安装

浅谈游戏安全 (一)

QT creator tips

老弹出explorer.exe遇到问题已停止工作,怎么办?

Sorting out of key vulnerabilities identified by CMS in the peripheral management of red team (I)

On Sunday, I rolled up the uni app "uview excellent UI framework"
Thank you for your recognition! One thank-you note after another

halcon知识:区域(Region)上的轮廓算子(2)
随机推荐
Industrial security experts talk about how to build security protection capability for government big data platform?
What is the difference between server leasing and hosting?
What does cloud desktop mean? What are the characteristics of cloud desktop?
Tencent cloud launched its new 100g+ cloud server product!! Expect more than 400g+ in the future!
Big coffee face to face | Dr. Chen Guoguo talks about intelligent voice
What is the difference between elasticity and scalability of cloud computing? What does elastic scaling of cloud computing mean?
Chapter 6: UART echo case of PS bare metal and FreeRTOS case development
Clickhouse optimize table comprehensive analysis
Use Charles to capture the package of the applet through the mobile agent
Use lightweight application server to automatically download and upload to onedrive
No monitoring information seen in kibana
Double 11 will arrive soon. Is your website ready?
左滑从小窗到大窗口DispatchFrameLayout
How to register a trademark? What needs to be prepared?
Highlights of future cloud native CIF Forum
What does cloud computing elasticity mean? What are its functions?
Three Scheduling Strategies in yarn
Summary of common SSH commands
Get to know MySQL database
Summary of common problems of real-time audio and video TRTC - quality