我在下面运行了这个带有几百个符号的symbol_list的程序,并且在某个时刻它表示没有足够的内存而我重复使用相同的变量为什么呢?
base-url: http://www.google.com/finance/historical
download-directory: "askpoweruser/stock-download/google/files/"
column-header: "Time;Open;High;Low;Close;Volume"
#debug: true
symbol_list: parse/all {GOOG AAPL MSFT INDEXDJX:.DJI} " "
ans: ask {symbols by default "GOOG AAPL MSFT INDEXDJX:.DJI": }
if (ans <> "") [symbol_list: parse/all ans " "]
;do code-block/2
foreach symbol symbol_list [
url0: rejoin [base-url "?q=" symbol]
dir: make-dir/deep to-rebol-file download-directory
either none? filename: find symbol ":" [
filename: symbol
url: rejoin [url0 "&output=csv"]
either not error? try [content: read url][
out-string: copy rejoin [column-header newline]
quotes: parse/all content ",^/"
reversed-quotes: reverse quotes
foreach [v c l h o d] reversed-quotes [
either not (error? try [d: to-date d]) [
d: rejoin [d/year "-" d/month "-" d/day]
append out-string rejoin [d ";" o ";" h ";" l ";" c ";" v newline]
][
;print [d "is not a date"]
;input
]
]
filename: rejoin [filename "_" "1440"]
write to-rebol-file rejoin [dir filename ".csv"] out-string
print filename
][
print ["Error for symbol" symbol]
]
][
filename: replace/all replace/all filename ":" "" "." ""
out: copy []
for i 0 1 1 [
p: i
url: rejoin [url0 "&start=" (p * 200) "&num=" ((p + 1) * 200)]
content: read url
rule: [to "<table" thru "<table" to ">" thru ">"
to "<table" thru "<table" to ">" thru ">"
to "<table" thru "<table" to ">" thru ">"
copy quotes to </table> to end
]
parse content rule
parse quotes [
some [to "<td" thru "<td" to ">" thru ">" [copy x to "<" | copy x to end] (append out replace/all x "^/" "")]
to end
]
if #debug [
write/lines to-rebol-file rejoin [dir filename "_" p ".html"] quotes
]
]
if #debug [
write to-rebol-file rejoin [dir filename "_temp" ".txt"] mold out
]
out-string: copy rejoin [column-header newline]
out: reverse out
foreach [v c l h o d] out [
d: parse/all d " ,"
d: to-date rejoin [d/4 "-" d/1 "-" d/2]
d: rejoin [d/year "-" d/month "-" d/day]
append out-string replace/all rejoin [d ";" o ";" h ";" l ";" c ";" v newline] "," ""
]
filename: rejoin [filename "_" "1440"]
write to-rebol-file rejoin [dir filename ".csv"] out-string
print filename
]
]
要获取符号列表,您可以使用此符号(rebol在字母H之前崩溃):
alphabet: [A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]
symbol-list: copy []
rule: [
to <table class="quotes">
some [ to {<A href="/stockquote} to ">" thru ">" copy symbol to "<" (append symbol-list symbol)]
to </table>
]
foreach letter alphabet [
content: read to-url rejoin ["http://www.eoddata.com/stocklist/NYSE/" letter ".htm"]
parse content rule
probe symbol-list
write/append %askpoweruser/stock-download/symbol-list-nyse.txt mold symbol-list
]
答案 0 :(得分:4)
你可以在你的一个循环中放置一个'STAT函数,试图弄清楚是否发生内存泄漏。
内存不足错误通常发生在以下某种情况或类似情况中:
附加到一个未在循环函数开头被清除或复制的系列
如果在树外部引用了一些(单个?)子元素并且整个数据块最终被捕获,则完整的数据树不会重置为无(在每个叶子和分支处)公羊无法自由
当打印一个非常大的字符串或大型对象的嵌套树时(例如VID面包含对完整样式的引用,因此打印一个大应用程序的窗口通常会失败。)。
< / LI>某些堆栈溢出(无休止的递归或循环)有时会被错误地报告为内存错误。
单个项目的分配呈指数级增长...就像图像一样!在两个轴上将每次通过乘以10时的分配...有效地增加两个数量级,这通常在n * 10k范围内的数字处失败。
GC中最大的项目有时根本不会根据次优的R2 GC释放(大图像可能有这种症状)。
递归解析规则正在创建数据,单个规则是无限的(它在[rule | none]等规则上发生得非常快。在这种情况下,没有实际上等同于永远。
答案 1 :(得分:3)
它没有问题。但有些说明:
instead:
read to-url rejoin ["http://www.eoddata.com/stocklist/NYSE/" letter]
you can use just:
read join http://www.eoddata.com/stocklist/NYSE/ letter
instead:
either not cond [1][2]
you should use:
either cond [2][1]
instead:
download-directory: "askpoweruser/stock-download/google/files/"
dir: make-dir/deep to-rebol-file download-directory
write to-rebol-file rejoin [dir filename "_temp" ".txt"] mold out
use:
download-directory: %askpoweruser/stock-download/google/files/
dir: make-dir/deep download-directory
write rejoin [dir filename %_temp.txt] mold out
what the hell means?!:
for i 0 1 1 [
p: i
url: rejoin [url0 "&start=" (p * 200) "&num=" ((p + 1) * 200)]
..