memory leaks,help me

Just starting out? Need help? Post your questions and find answers here.
shu7734
User
User
Posts: 30
Joined: Thu May 15, 2008 5:53 am

memory leaks,help me

Post by shu7734 »

whereis memory leaks?

after few minute, memory used too big,

Code: Select all

*Content = AllocateMemory(65536)  
Repeat
ConnectionID = OpenNetworkConnection("xxx.xxx.xxx", 80) 
  If ConnectionID  

        
          Res = SendNetworkData(ConnectionID,@com$,Len(com$))  
          
            Repeat  
              Delay(10)  
              
            Result = NetworkClientEvent(ConnectionID)  
           
            Select Result  
           
            Case #PB_NetworkEvent_Data  
              
              Repeat
              FillMemory(*Content,65536)
              Result=ReceiveNetworkData(ConnectionID,*Content,65536) 
              recevstr.s=recevstr.s+PeekS(*Content)
            Until Result<1
\
            If CreateRegularExpression(0, "xxxxxxx\d+")
                Dim Result$(0)
                NbFound = ExtractRegularExpression(0, recevstr.s, Result$())
                For k = 0 To NbFound-1
                  QuerySQL.s="INSERT INTO "+Chr(34)+"want"+Chr(34)+"("+Chr(34)+"num"+Chr(34)+") VALUES("+Result$(k)+")"
                  DatabaseUpdate(99, QuerySQL.s) 
                Next
                FreeRegularExpression(0)

              Else
                Debug RegularExpressionError()
              EndIf
 \
              CloseNetworkConnection(ConnectionID)  
              Break
            EndSelect  
             
            Until Ok = 1  
  EndIf  
ForEver
Win7X64 Purebasic5.22x86DEMO
shu7734
User
User
Posts: 30
Joined: Thu May 15, 2008 5:53 am

Re: memory leaks,help me

Post by shu7734 »

replace Break to OK=1

is better but still memory leaks
Win7X64 Purebasic5.22x86DEMO
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: memory leaks,help me

Post by Bisonte »

This example is not working, but I think that your string recevstr.s grow up....

in every loop you add the received datas to it....

You should insert after your DatabaseUpdate a

Code: Select all

          If CreateRegularExpression(0, "xxxxxxx\d+")
            Dim Result$(0)
            NbFound = ExtractRegularExpression(0, recevstr.s, Result$())
            For k = 0 To NbFound-1
              QuerySQL.s="INSERT INTO "+Chr(34)+"want"+Chr(34)+"("+Chr(34)+"num"+Chr(34)+") VALUES("+Result$(k)+")"
              DatabaseUpdate(99, QuerySQL.s)
            Next
            FreeRegularExpression(0)
            
          Else
            Debug RegularExpressionError()
          EndIf
          
          recevstr.s = "" ; <--- This to clean up the string
If you don't want it anymore....
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
Post Reply