メモリに大量のSpatialPolygonsDataFrame
オブジェクト(1.4Gb)をロードして解析を実行し、オブジェクトを削除しようとするプログラムがあります。ただし、システムコマンドfree
を使用してシステムメモリを見ると、Rセッションがリセットされるまでオブジェクトが残っていることがわかります。 私はSpatialPolygonsDataFrame
それぞれ、世界地図の大規模なリストを作成するrworldmap
とrworlxtra
パッケージを使用してメモリリークを再現することができ、その後、それらを削除しようとしている:メモリリークの原因となる大きなSpatialPolygonsDataFrame
install.packages("sp")
install.packages("rworldmap")
install.packages("rworldxtra")
library(sp)
library(rworldmap)
library(rworldxtra)
these.maps.large <- lapply(1:100, function(x) assign(paste0("a_", x), getMap(resolution = "high")))
these.maps.smaller <- lapply(1:20, function(x) assign(paste0("a_", x), getMap(resolution = "high")))
# This frees the memory
rm(list="these.maps.smaller")
gc(reset=T)
# This fails to free the memory
rm(list="these.maps.large")
gc(reset=T)
EDIT ここでは、システム2を呼び出すための出力であります(「無料」)。
Restarting R session...
> library(sp)
> library(rworldmap)
### Welcome to rworldmap ###
For a short introduction type : vignette('rworldmap')
> library(rworldxtra)
> system2("free")
total used free shared buff/cache available
Mem: 131987656 1386468 118712292 540008 11888896 129731040
Swap: 4194300 3505464 688836
> these.maps.large <- lapply(1:100, function(x) assign(paste0("a_", x), getMap(resolution = "high")))
> system2("free")
total used free shared buff/cache available
Mem: 131987656 2708040 117390660 540008 11888956 128409404
Swap: 4194300 3505464 688836
> rm(list="these.maps.large")
> gc(reset=T)
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 585803 31.3 9601876 512.8 585803 31.3
Vcells 711198 5.5 96623732 737.2 711198 5.5
> system2("free")
total used free shared buff/cache available
Mem: 131987656 2708428 117390424 540008 11888804 128409168
Swap: 4194300 3505464 688836
Restarting R session...
> library(sp)
> library(rworldmap)
### Welcome to rworldmap ###
For a short introduction type : vignette('rworldmap')
> library(rworldxtra)
> system2("free")
total used free shared buff/cache available
Mem: 131987656 1386696 118711988 540008 11888972 129730744
Swap: 4194300 3505464 688836
> these.maps.smaller <- lapply(1:20, function(x) assign(paste0("a_", x), getMap(resolution = "high")))
> system2("free")
total used free shared buff/cache available
Mem: 131987656 1699628 118399100 540008 11888928 129417836
Swap: 4194300 3505464 688836
> rm(list="these.maps.smaller")
> gc(reset=T)
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 702817 37.6 2564361 137.0 702817 37.6
Vcells 966452 7.4 21638748 165.1 966452 7.4
> system2("free")
total used free shared buff/cache available
Mem: 131987656 1699612 118399116 540008 11888928 129417852
Swap: 4194300 3505464 688836
は、誰もがこのような場合、セッションをリセットすることなく、これらの大規模なSPのオブジェクトの1つを除去することができるかもしれませんどのような方法である理由を任意のアイデアを持っていますか?
Rバージョン3.2.3(2015年12月10日) プラットフォーム:x86_64版-redhatの-のlinux-gnuの(64ビット) の下で実行:科学のLinux 7.2(窒素)