go-processing string causes memory overflow

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Today with go to do the character "+" connection operation, each connection string roughly about 10M, loop connected 100 times, directly caused the go memory overflow.

//Text Project Main.goPackage Mainimport ("Io/ioutil"    "Log"    "OS") Func main () {log. Println ("Start") UserFile:="D:\\txt\\2.txt"    //Read the fileReadbuf, _: =Ioutil. ReadFile (UserFile)//Word Data processingLog. Println ("Start processing Data") Strcontent:=string(READBUF) forI: =0; I < -; i++{strcontent+ = Strcontent +"Gas Money"} log. Println ("end of data processing") BUF:= []byte(strcontent)//Write a fileIoutil. WriteFile (UserFile, buf, OS. modeexclusive)}

The reported exception:

Runtime:out of Memory:cannot Allocate 335872000-byte block (998440960 in use)

Fatal error:out of Memory

The same business logic with NET to handle is normal operation, there is no memory overflow situation, it seems golang garbage collection and content distribution is not mature enough, need to strengthen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.