找回密码
 加入
搜索
查看: 16504|回复: 22

[AU3基础] 程序长时间运行出现error allocating memory错误

  [复制链接]
发表于 2011-12-7 11:47:43 | 显示全部楼层 |阅读模式
代码如下 ,长时间运行就会出现如图错误,请大家帮忙看看,
谢谢啦
#cs ____________________________________

#ce _______________脚本开始_________________

#include <FTPEx.au3>
#include "CoProc.au3"
#include <misc.au3>
While 1
        $iPidotherfuc = _CoProc("ftp")
        ;ftp()
        Sleep(10000)
#CS         If ProcessExists($iPidotherfuc) Then
                   ProcessClose($iPidotherfuc)
           endif        
#CE
WEnd        

Func ftp()        
        _Singleton("ftpfunc",0)
        Dim $downftpfileflag
        Dim $fFailIfExists
        ;$server = ''
        $server = ''
        $username = 's1'
        $pass = 'fin23'
        
        $Open = _FTP_Open('SlipFinder ftp ')
        $Conn = _FTP_Connect($Open, $server, $username, $pass)                
        ;MsgBox(0,"$Conn",_FTP_DirGetCurrent($Conn),1)
        If $Conn <> 0 Then                
                $aFile = _FTP_ListToArray($Conn, 2)                ;只找文件
                If IsArray($aFile) Then 
                        Sleep(2000)                        ;等待下,以防止机台产生数据中                        
                        For $i= 1 To $aFile[0]        
                                ;MsgBox(0,"",$aFile[$i],1)
                                $sourcefile = "/" & $aFile[$i]                
                                $targetfile = "C:\Slip" & $aFile[$i]                
                                ;$filegroup=StringSplit($aFile[$i],".")
                                ;MsgBox(0,"",$filegroup[2])
                                ;If $filegroup[2] = "txt" Then                        ;如果是txt档,则下载此文件
                                        $downftpfileflag=_FTP_FileGet($Conn,$sourcefile,$targetfile, $fFailIfExists = False,0,$INTERNET_FLAG_TRANSFER_ASCII)        ;false为不覆盖
                                        ;MsgBox(0,"上传标志",$downftpfileflag ,1)
                                        If $downftpfileflag = 1 Then                 ;判断是否下载成功,成功即可删除
                                                _FTP_FileDelete($Conn, "/" & $aFile[$i])
                                                ;MsgBox(0,"文件夹名",$filegroup[1])
                                                ;_FTPRemovedir($Conn, "/" & $filegroup[1]) ; 删除产生的文件夹
                                                ;MsgBox(0,"","上传后删除啦",1)
                                        Else                                ;如果下载不成功,
                                                ;MsgBox(0,"@error",@error,1)
                                                ;$downftpfileflag=_FTP_FileGet($Conn,"/" & $aFile[$i] ,"C:" & $aFile[$i], $fFailIfExists = False)        
                                        EndIf
                                ;Else                                         ;如果不是txt档,则直接删除 
                                        ;_FTP_FileDelete($Conn, "/" & $aFile[$i])
                                        ;MsgBox(0,"","直接删除啦",1)
                                ;EndIf                                
                        Next                        
                EndIf                        
        EndIf        
        $Ftpc = _FTP_Close($Open)
EndFunc

Func _FTPRemovedir($l_FTPSession, $sFTPDirectory)
    Local $aFile, $hSearch, $sWorkingdir, $sFolderlist, $i, $bFirst, $aFolderStack[2] = [1, $sFTPDirectory]
    While $aFolderStack[0] > 0
        $sWorkingdir = $aFolderStack[$aFolderStack[0]]
        $aFolderStack[0] -= 1
        $aFile = _FTP_FindFileFirst($l_FTPSession, $sWorkingdir & '/*', $hSearch, $INTERNET_FLAG_NO_CACHE_WRITE)
        If Not @error Then
            $bFirst = True
            While 1
                If $bFirst = False Then
                    $aFile = _FTP_FindFileNext($hSearch)
                    If @error Then ExitLoop
                EndIf
                If $aFile[1] = 16 Then; If file is a directory we are going to add it to the stack of folders we need to go through
                    $aFolderStack[0] += 1
                    If UBound($aFolderStack) <= $aFolderStack[0] Then ReDim $aFolderStack[UBound($aFolderStack) * 2]
                    $aFolderStack[$aFolderStack[0]] = $sWorkingdir & "/" & $aFile[10]
                    $sFolderlist &= $sWorkingdir & "/" & $aFile[10] & ';'; Here I am adding the folder to a list of directorys I need to delete later
                Else; else we delete it
                    _FTP_FileDelete($l_FTPSession, $sWorkingdir & "/" & $aFile[10])
                    ConsoleWrite('File: ' & $sWorkingdir & "/" & $aFile[10] & ' Deleted' & @CRLF)
                EndIf
                $bFirst = False
            WEnd
        EndIf
        _FTP_FindFileClose($hSearch)
    WEnd
    $aFolderStack = StringSplit(StringTrimRight($sFolderlist, 1), ';')
    For $i = $aFolderStack[0] To 1 Step -1 ;Here we delete all those empty folders from last to first
        _FTP_DirDelete($l_FTPSession, $aFolderStack[$i])
        ConsoleWrite('Directory: ' & $aFolderStack[$i] & ' Deleted' & @CRLF)
    Next
    _FTP_DirDelete($l_FTPSession, $sFTPDirectory);Delete the original directory
   EndFunc   ;==>_FTPRemovedir

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-12-8 12:49:41 | 显示全部楼层
自己顶下哦,下沉了
发表于 2011-12-8 20:12:14 | 显示全部楼层
好巧,我也有这个问题,好像内存使用过大超限
 楼主| 发表于 2011-12-11 21:11:33 | 显示全部楼层
回复 3# tryhi
请问这个问题,你是怎么解决的?怎么解决的呀?
发表于 2011-12-11 21:41:16 | 显示全部楼层
加这段释放内存代码试一下效果可否。
_ReduceMemory(@AutoItPID)
Func _ReduceMemory($i_PID = -1)
        If $i_PID <> -1 Then
                Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
                DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
        Else
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
        EndIf

        Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory
 楼主| 发表于 2011-12-12 10:44:48 | 显示全部楼层
回复 5# 半芯蕃茄

感谢,,我测试下,估计要一个星期以后才会报错。
谢谢
 楼主| 发表于 2011-12-16 09:29:08 | 显示全部楼层
回复 5# 半芯蕃茄


    Dear 半芯蕃茄,加上你提供的代码,内存使用虽然大幅减小,
但一个星期下来,依然出现以上问题 ,
发表于 2011-12-16 21:34:35 | 显示全部楼层
回复 7# leon460


    那看来要等高手解答了,或许你可以设定程序在运行一定时间后自动关闭后重启程序本身
发表于 2011-12-16 22:02:11 | 显示全部楼层
楼主确定你运行出错的脚本就是上面的,没有修改?
另外,你得确定是内存漏了,还是超过使用额了:http://msdn.microsoft.com/en-us/library/aa366778(v=vs.85).aspx#memory_limits

若上传下载个超大文件(如超过500M),就可能出现这种错误。比如用_FileCountLines()函数于500M的文本,可能就需要差不多峰值3G的内存才能操作。
 楼主| 发表于 2011-12-19 15:14:28 | 显示全部楼层
回复 8# 半芯蕃茄

实在没有办法了,我就只有这样做了
 楼主| 发表于 2011-12-19 15:14:49 | 显示全部楼层
回复 9# happytc

所有的代码已经贴出了,呵呵,,
发表于 2011-12-20 16:53:03 | 显示全部楼层
用过的数组要记得清掉,我写过一个就有这情况,不定时间,运行久了就无故自己退出,或者是出错,之后我把用过的临时数组在函数返回时清掉,就没有问题了,目前稳定运行几十小时不再出错。
 楼主| 发表于 2011-12-21 14:56:40 | 显示全部楼层
回复 12# 曼菲士


    能贴出简单的代码示例下么,谢谢
发表于 2011-12-21 17:56:04 | 显示全部楼层
本帖最后由 曼菲士 于 2011-12-21 17:57 编辑

下面是P版的一段代码,我改了些

Local $tmpParameter = StringSplit(StringRight($PingParameter, StringLen($PingParameter) - 10), "|")
If IsArray($tmpParameter) Then
        Local $aBuffer[UBound($tmpParameter)], $iUBound = UBound($aBuffer)
        Local $aThread[$iUBound], $aResult[$iUBound][3]
        For $i = 1 To $iUBound - 1
                $aBuffer[$i] = DllStructCreate($tagSEND_ARP)
                DllStructSetData($aBuffer[$i], "IpAddress", $tmpParameter[$i])
                $aThread[$i] = _RTCreateThread($pStartAddr, DllStructGetPtr($aBuffer[$i]))
                If ($aThread[$i] < 1) Then
                        FileWrite(@ScriptDir & "\Error.txt", "Error: " & @error & " Error creating thread, index: " & $i & @CRLF)
                        exit
                EndIf
        Next

        For $i = 1 To $iUBound - 1
                If _RTWaitForObject($aThread[$i]) Then
                        FileWrite(@ScriptDir & "\Error.txt", "Error: " & @error & " Error waiting for thread to complete, index: " & $i & @CRLF)
                EndIf
                _RTCloseHandle($aThread[$i])

                $aResult[$i][0] = DllStructGetData($aBuffer[$i], "IpAddress")
                $aResult[$i][1] = DllStructGetData($aBuffer[$i], "MacAddress")
                $aResult[$i][2] = DllStructGetData($aBuffer[$i], "Error")
                $aBuffer[$i] = 0        ;清除代码
        Next
        $aBuffer = 0 ;清除数组
        $aThread = 0 ;清除数组
        $aResult = 0 ;清除数组
EndIf
$tmpParameter = 0 ;清除数组
 楼主| 发表于 2011-12-22 09:18:44 | 显示全部楼层
回复 14# 曼菲士

是不是就可以理解为 就是将数组重置为0 哈 (一行代码就够了?)

$aBuffer = 0 ;清除数组
    $aThread = 0 ;清除数组
    $aResult = 0 ;清除数组
    $tmpParameter = 0 ;清除数组

以上例子就是你标出的部分
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-20 19:50 , Processed in 0.097014 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表