Manually release memory in Puppeteer - memory

I scroll over an infinite scroll page using Puppeteer. As you can imagine, the memory grows and is never flushed. In order to lower the memory need, I decided to remove the loaded DOM every once in a while. While the browser is much faster to scroll, the memory remains the same.
I wanted to know how I can tell Puppeteer to flush its memory when the page is almost empty each time I remove the loaded DOM? Logically, the memory need should be extremely low. Maybe a garbage collection trigger would help? Anything I can do to release the memory?

Related

iOS - Terminated due to memory issue

I'm having a memory issue with one specific ViewController and memory. When I launch my app in debug mode, it launches with 40mb memory usage. (I have no idea if this is already a lot or not -- what is common?). Then, when I open this specific view, it spikes up to about 120mb. The issue is, when I pop this view (with the navigationController popViewController), the memory stays up at 120mb. And then, when I re-open it, it spikes to 200mb (a 80mb increase every time).
With other similar ViewController it spikes up to 120mb too, but when I close the view, it goes back down to more or less 40mb.
The problem is that this specific view contains quite a bit of code (about 1000 lines...) and it's impossible for me to post everything here.
What methods should I use to specifically locate the issue in xCode?
For anyone I might be able to help with this:
use the tools in xCode as recommended. There are some great tutorials online.
In my case it was an issue with an [NSTimer] which kept a strong reference to my view, so it never got released afterwards, thus stacking up memory. Make sure to stop your time when you pop a view.

memory leak between page reloads on safari in ios

I have a three.js website which when loaded in mobile safari on iphone takes up ~450mb(I found this through "Instruments" utility in XCode).
Now, when I reload this page, the inspector shows that the memory is now ~550mb. And, the next time I reload the page, it crashes altogether(probably due to crossing the memory limit of 640mb?)
I've tried:
Disabling renderer.render calls(three.js sends data from main memory to GPU memory during renderer.render) so nothing is sent to GPU, in this case the memory was ~280mb but still, it was increasing with page reloads.
Disabling caching on the main page.
Freeing up almost all the resources both in main memory and in GPU memory as suggested here.
Set any/all images src to 1px data URL as suggested here.
But, the page still crashes due to increased memory between reloads. So, I am confused as to what keeps the browser from freeing up the memory. Any clues?

Memory result from Xcode is different to Instrument

I am trying to see how much memory my program uses and identify leaks. I have tried looking at the memory page built into xcode and also the Allocation instrument. They get totally different result though (Both simulated on my 6s).
An outline of what I did...
I have a tableview that loads images from firebase. My test was keep pressing "reload all data" button at 3 second interval for a bit (30 seconds) and observe how the memory reflects what I did. Below are the results of the two screen shots.
What is weird is that for xcode result, I see that my memory just continues to climb higher and higher upon every refresh (Which suggests that I have a leak somewhere as the table view should discard the original data and load new ones. So I would expect highs and lows). So I went into the allocation instrument and did the same test. However, what I instead see is that the total persistent byte doesnt grow as crazy as before and remains hovering around 23.36mb with minor highs and lows (As what I might expect for reloading a table?)
Any explanations?
-- Update--
The answer here appears to contradict to what I believe is right
Xcode Memory Graph - showing increasing memory use - what exactly does it show?
Because I have tried hitting the refresh button for an hour to let the memory build up to nearly 1.5GB and I did get a memory warning. So I dont believe Xcode is showing "total bytes".

UIWebView memory leak

I have an iPad app (IOS 4.3 & 5.0) that is creating a UIView with at least 2 subviews every time the user pages forward or backward. The 2 subviews are UIWebView objects.
On every relevant swipe the old UIWebViews are removed and deallocated properly (removeFromSuperview then stopLoading and set delegate to nil) and the parent UIView is deallocated. I can confirm that both parent UIView and the 2 child UIWebViews are absolutely gone.
I can see the retain count on the webviews as they are being removed and I am quite sure that they are indeed removed every time.
However my memory allocation continues to increase on every swipe by ~200-350k . No leaks in instrument but I can see the memory usage going up slowly.
On iPad 1 the app eventually (within 6-10 minutes of moderate usage) receives multiple memory warnings and is terminated. LowMemory crash log...etc is generated.
We use stringByEvaluatingJavaScriptFromString and loadRequest to populate the Webviews. Memory usage creeps up even when nothing is injected or loaded into the webViews.
Is anybody experiencing this kind of behavior with UIWebViews ? Has anyone dealt with this successfully ?
Thoughs, comments & answers would be greatly appreciated.
Try to use Instruments but with the "Allocations" template and watch the "# Living" columns for UIWebView. I usually use it like this:
Profile app with Allocations template
"Warn up" the app by going thru all tabs, scroll around etc.
Press "Mark Heap", this will create a "Baseline" heapshot
Do the thing you think causes objects to stay around
Press "Mark Heap" again, this will create a "Heapshop #" heapshot
Inspect the objects in "Heapshop #" which will show size and number of objects created and alive since the last heapshot.
Goto 4
Not aware of any leak, but if you are destroying and re-creating the same view hierarchy every swipe, why not store the views and re-use them instead?
Regardless of whether they leak, webviews are computationally expensive to set up, so re-using them and just reloading the content should give you a performance boost, and may solve your leak as well.
are you still seeing this issue? I traced something which looks like unbounded memory usage (not necessarily a leak, but I get low memory warnings and eventual process termination) by calling stringByEvaluatingJavaScriptFromString over and over:
[webview stringByEvaluatingJavaScriptFromString:#"something()"];
It seems like there is something odd there.

Image Question for iPad - Memory issues

So I installed my app on my ipad and it crashes due to a memory issue. I figured this was because I'm using really big image files so I went back and reduced them all and essentially cut out about 75% of their size by resizing them and then using PNGCrush.
Now, as for running the program, if I have a background image for each of my 4 individual tabs, would it save memory if I were to set the images to Null every time I switch tabs or should I leave them set? I have one page which has a couple dozen images on it as they act as buttons and from what I'm hearing it sounds like I should clear them all when I'm not viewing that page. Is that correct?
Right now when I boot up, I load all of the images for everything in the app in a sort of: "load it now and be done with it" mentality, though from what I've been reading that causes memory issues as there isn't much memory to use. Does this mean every time I switch tabs or views I want to clear all the images from the ones that aren't visible and then reload them when we go back to them? Would this cause an increase in performance? Or at least prevent crashes? My program works in the simulator but when I run it on my ipad it just explodes =/
Thanks!
EDIT: I'm using Monotouch BTW hence everything is in C#
UIImage BG = UIImage.FromFile("Images/Makes/explosion.png");
UIImage basic = UIImage.FromFile("Images/Models/camaro.png");
UIImage advance = UIImage.FromFile("Images/search.png");
AdvancedSearchButton.SetBackgroundImage(advance, UIControlState.Normal);
ImageSearchButton.SetBackgroundImage(basic, UIControlState.Normal);
MainBG.Image = BG;
BG.Dispose();
basic.Dispose();
advance.Dispose();
Now I know in regular C# dispose() doesn't actually "free" memory, but I read something that says that it gets converted to a "release" when it compiles over to obj-c so that would essentially be freeing those objects.
Also, I'm wondering if I would need to dispose() of the individual buttons and the image after I'm no longer viewing them. I was just setting the image to NULL but that gave me errors.
MainBG.Dispose();
AdvancedSearchButton.Dispose();
ImageSearchButton.Dispose();
Thanks so much for the help!
EDIT2:
So I just tried the above code and the background images and everything else are still there and appears as if nothing is actually getting cleared. Suggestions?
The iPhone does not have virtual memory and it does not have garbage collection. So once something is loaded in the memory it stays in the memory until your code explicitly releases it. If you are not using some resources, you should definitely clean them up as soon as possible.
Also, you should listen to low memory warnings from iOS, which is another opportunity for your code to do some internal clean up.
First off, lazy load your resources unless you have a justifiable reason not to. Secondly, I'm not sure how big your images are, but on large images (ones that are by nature intended for things like backgrounds, or otherwise), generally speaking, I will chop them up into chunks, and load them, again you guessed it, lazily as they're needed.
What you should do is handle your memory warnings properly. Deallocate any resources that are not absolutely critical -- i.e., items on other views in other tabs, or hidden content. You can load them again when you have to.
You should also take a look at using Instruments to find out if you leak (I'm hoping you've already done this), examine your program to see if you can persist some cached resources to disk during low memory situations, etc.

Resources