memory-management

Deleting large Javascript objects when process is running out of memory

拜拜、爱过 提交于 2019-12-23 08:55:08
问题 I'm a novice to this kind of javascript, so I'll give a brief explanation: I have a web scraper built in Nodejs that gathers (quite a bit of) data, processes it with Cheerio (basically jQuery for Node ) creates an object then uploads it to mongoDB. It works just fine, except for on larger sites. What's appears to be happening is: I give the scraper an online store's URL to scrape Node goes to that URL and retrieves anywhere from 5,000 - 40,000 product urls to scrape For each of these new URLs

How do i explicitly clear the byte[]

耗尽温柔 提交于 2019-12-23 08:54:30
问题 I am creating new byte arrays which are not being collected by GC and are living in memory and increasing the private bytes. The code below gets executed every 10 seconds. How do I explicitly clear the variable after I am done with it? byte[] outputMessage = new byte[10000]; //Do some work here 回答1: How do you know they are not being collected? The code you provide is fine, and it should become eligible for collection if you don't have any dangling references to it. Explicitly, you can clear

Resolve 'Out of memory' exception when calling DrawImage

旧城冷巷雨未停 提交于 2019-12-23 08:51:40
问题 About one percent of our users experience sudden crash while using our application. The logs show below exception, the only thing in common that I've seen so far is that, they all have XP SP3. Thanks in advance Out of memory. at System.Drawing.Graphics.CheckErrorStatus(Int32 status) at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr

how to calculate size of pointer pointed memory?

≡放荡痞女 提交于 2019-12-23 08:36:07
问题 In one function I have written: char *ab; ab=malloc(10); Then in another function I want to know the size of memory pointed by the ab pointer. Is there any way that I can know that ab is pointing to 10 chars of memory? 回答1: It's a deep secret that only free() knows for sure. It's likely in your system, but in a totally implementation dependent manner. A bit awkward, but if you want to keep everything together: typedef struct { // size of data followed by data (C only trick! NOT for C++) int

how to calculate size of pointer pointed memory?

自古美人都是妖i 提交于 2019-12-23 08:35:25
问题 In one function I have written: char *ab; ab=malloc(10); Then in another function I want to know the size of memory pointed by the ab pointer. Is there any way that I can know that ab is pointing to 10 chars of memory? 回答1: It's a deep secret that only free() knows for sure. It's likely in your system, but in a totally implementation dependent manner. A bit awkward, but if you want to keep everything together: typedef struct { // size of data followed by data (C only trick! NOT for C++) int

Haskell: Data.HashSet (from unordered-container) Performance for Large Sets

妖精的绣舞 提交于 2019-12-23 08:14:22
问题 The data First of all, let's generate some input so we have concrete data to talk about: python -c 'for f in xrange(4000000): print f' > input.txt this will generate a file input.txt containing the numbers from 0 to 3999999, each on its own line. That means we should have a file with 4,000,000 lines, adding up to 30,888,890 bytes, roughly 29 MiB. Everything as a list Right, let's load everything into memory as a [Text] : import Data.Conduit import Data.Text (Text) import Control.Monad.Trans

Haskell: Data.HashSet (from unordered-container) Performance for Large Sets

不打扰是莪最后的温柔 提交于 2019-12-23 08:13:36
问题 The data First of all, let's generate some input so we have concrete data to talk about: python -c 'for f in xrange(4000000): print f' > input.txt this will generate a file input.txt containing the numbers from 0 to 3999999, each on its own line. That means we should have a file with 4,000,000 lines, adding up to 30,888,890 bytes, roughly 29 MiB. Everything as a list Right, let's load everything into memory as a [Text] : import Data.Conduit import Data.Text (Text) import Control.Monad.Trans

Haskell: Data.HashSet (from unordered-container) Performance for Large Sets

被刻印的时光 ゝ 提交于 2019-12-23 08:13:07
问题 The data First of all, let's generate some input so we have concrete data to talk about: python -c 'for f in xrange(4000000): print f' > input.txt this will generate a file input.txt containing the numbers from 0 to 3999999, each on its own line. That means we should have a file with 4,000,000 lines, adding up to 30,888,890 bytes, roughly 29 MiB. Everything as a list Right, let's load everything into memory as a [Text] : import Data.Conduit import Data.Text (Text) import Control.Monad.Trans

Using .reset() to free a boost::shared_ptr with sole ownership

送分小仙女□ 提交于 2019-12-23 08:08:21
问题 I'm storing an object ( TTF_Font ) in a shared_ptr that is provided to me from a third-party API. I cannot use new or delete on the object, so the shared_ptr is also provided a "freeing" functor. // Functor struct CloseFont { void operator()(TTF_Font* font) const { if(font != NULL) { TTF_CloseFont(font); } } }; boost::shared_ptr<TTF_Font> screenFont; screenFont = boost::shared_ptr<TTF_Font>( TTF_OpenFont("slkscr.ttf", 8), CloseFont() ); If, later, I need to explicitly free this object is it

High memory usage with Console.WriteLine()

 ̄綄美尐妖づ 提交于 2019-12-23 07:58:15
问题 public static void Main() { int size = 250000; var a = new int[size]; for (int i = 0; i < size; i++) Console.WriteLine("{0}", a[i]); } When I tested the above code with CLRProfiler, it told me that the code allocates roughly 40 MB. Around 20 MB is allocated to String , 9 MB to Char[] , 5 MB to StringBuilder and 3 MB to Int32 . public static void Main() { int size = 250000; var a = new int[size]; for (int i = 0; i < size; i++) Console.WriteLine("0"); } This one allocates around 5 MB. 4 MB is