Page 1 of 1

memory leaks,help me

Posted: Sat Feb 25, 2012 9:56 am
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

Re: memory leaks,help me

Posted: Sat Feb 25, 2012 10:05 am
by shu7734
replace Break to OK=1

is better but still memory leaks

Re: memory leaks,help me

Posted: Sat Feb 25, 2012 10:27 am
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....