How to deal with memory leaks in a virtual machine by closing the browser correctly

    image
    One of the most common questions that users of Parallels Desktop ask us (as well as probably all other virtual machines) is how to make virtual machines consume less memory. This is asked by a huge number of people on forums and social networks.
    Therefore, we always look at exactly which programs and technologies require more memory when working with a virtual machine in PD. And that's what they found.

    The "torn" operation of a virtual machine, its frequent and dense freezing, starts from the moment when too many applications are running on the host that require more memory than the host can physically provide. In addition, the guest OS can start to slow down if it runs many heavy applications or even just one or two, but it is very memory-hungry.

    Unfortunately, there is no universal advice on maintaining the optimal balance between guest and host memory. Just because people have too different usage scenarios and combinations of the programs currently running. For example, someone in a virtual machine wants to run a 3D game, the minimum requirements of which are 2 GB of RAM, while on the host at that moment he does not need anything other than the Parallels Desktop solution itself. And someone, on the contrary, works simultaneously with the browser and several different types of documents on the host OS, and he needs a virtual machine with Windows only for a small application, the analogue of which does not exist under Mac. Obviously, in the first case, a person needs to allow the virtual machine to use more host memory (without going beyond the recommended maximum, of course), and in the second case, on the contrary, it would be better to limit the memory of the guest OS to a minimum. (In Parallels Desktop, this can be done in the top menu.Virtual Machine , then Configure , then General . But first you need to turn off the virtual machine).

    The main thing to remember is that physical memory is not infinite. If a person needs to constantly use heavy host and guest applications at the same time, and he is constantly faced with brakes, he should consider adding a couple more gigabytes of RAM to his Mac. But the main reason for the lack of memory for some users still is that they forget (or do not see the need) to close applications that they no longer need, and minimize or even leave their windows hanging in the background. This is especially true for laptop users, in which the presence of a battery allows you not to turn off the host between uses. Such applications continue to occupy memory. And if they also cause the so-called memory leaks,

    Leaks, in addition to resource-intensive applications, are also provoked by some antiviruses and extensions of various third-party software for browsers. But, as it turned out, most of all complaints are caused by Adobe Flash. It is this technology that uncontrollably and randomly devours memory and at the same time does not release it back. We even calculated: in 99% of cases when Parallels Desktop users complained about freezes, it was the flash that was to blame, and not the virtual machine at all.

    Why it happens? Everyone loves surfing the Internet, many devote several hours a day to this business. And on the Internet there are a lot of websites with banners that work on flash (or even have web resources entirely on flash, for example, flash games or business card sites of especially creative firms). A person launches a browser on his Mac (Safari) and starts surfing, opening one site after another in different tabs (and many people like to bring this number to almost fifty).

    By the way, this summer we set up an experiment in the Gizmodo tech blog to check how much each open tab consumes (both in Safari and other browsers), and found out that it was 0.19 watts. And opening 100 tabs even without any flash generally reduces battery life by more than an hour.image


    A certain amount of operating system memory is allocated under the browser. If you surf for a long time, then the cache naturally overflows, and the data is dumped to the hard drive in the Swap file (swap file). And now a surprise: if the browser is only minimized (and not closed completely) and left to “hang” there long enough (for example, the entire working week), then a huge amount of data will accumulate in it.

    In the case of Flash, such memory leaks occur very slowly and are almost not noticeable to the user. As a result, in a few days, an average of 3-4 gig accumulates. Some of the Mac OS data has already been sent to its swap file. Problems begin just at the start of the virtual machine: MacOS is forced to look for a lot of memory under the new process. This leads to the fact that it throws a huge amount of data from the cache into a swap - it tries to free up memory for launching the virtualization tool and the guest OS. At this point, the virtual machine is trying to read the data needed to start it. All together leads to an increase in the number of random accesses to the disk, and the system begins to "slow down".

    So take a look at the Swap used parameter in Activity Monitor. If the amount of data there is gradually growing and has become clearly more than 1 GB, then it is likely that some application does not release its memory.
    image

    And what to do? And prevention of this particular problem is very simple - periodically you need to close the entire browser using Cmd + Q (and not just close the window by clicking on the red brake light in the upper left corner).

    You can also apply a few more hints to prevent leaks. For example, to put an ad blocker that will get rid of flash banners, there are quite a lot of them on the market now - from the popular Adblock (which blocks ads before it is loaded) to PithHelmet and GlimmerBlocker, or something like the ClickToFlash plugin that blocks Flash in Safari replacing it with static images.

    Secondly, it would be nice to remove various browser extensions that also cause leaks (for example, antiviruses or Skype). In Safari, this is done in the settings window (Safari - Preferences - Extensions), where you can both uninstall extensions and generally prohibit the installation of any add-ons. Just delete a little - you still need to check in the ~ / Library / Safari / Extensions folder to see if the excess is behind them.

    If you have any other tips for dealing with memory leaks, then we were waiting for you in the comments.

    Also popular now: