Tuesday, March 9, 2010

Who likes Mondays?

I do *not*. But today, I like them less than usual.

First: since two days, Saturday and Sunday, are more than enough to upset my biological clock, returning to the weekly routine is pretty hard for me. I try to tame my nocturnal instincts but constraining that little Count Dracula inside me is harder and harder.

Second: winter is not exactly my favorite season to go out of the bed, undress and have a shower. Particularly when the average outdoor temperature is about -5 degree Celsius and the memory of the warmth beneath the blankets is still vivid inside my mind. Despite that, and after the first coffee, the week has begun and Sunday just seems so far away.

Monday is the day of "good intentions": an entire working week is there before you, and it's the perfect day to schedule executive meetings.

So simple were my plans and, for a time, I wasn't late either. But I'd reckoned without my... clutch. Yep. The gear lever was stuck and the clutch pedal seemed to offer few or no resistance. Bad news. I called a crane, waited for it in a chilly and busy street of Madrid. It finally took me to the nearest garage just to discover that your bank account will shortly be drained. Ah, I almost forget! The icing on the cake: I never arrived to that meeting.

Who likes Mondays? I don't know. But I certainly do not.

Sunday, March 7, 2010

Is Safari leaking memory?

I was working at some Java EE application with my MacBook while I realized that I was running out of memory. Strange, isn't it? I was just running the following:

Not so much for a MacBook equipped with a 4GB of RAM to experience a memory shortage. When I opened the Activity Monitor I was shocked to discover that my MacBook experience was jeopardized by the Safari web browser.

Since then, I'm monitoring Safari resource consumption. I've also been searching for information about Safari leaks and it seems that since a long time there are "outstanding" memory leaks which, apparently, haven't been corrected so far.

After using Safari some time that's what I see:


Although I'm reasonably happy with Safari speed, almost one gigabyte is simply too much for some newspaper reading and a maximum of a couple of tabs open. I'm seriously thinking about switching to Google Chrome.


Apple Mac OS X' "Safe Sleep"

Safe sleep is no new kid on the block: at least as far as it concerns major operating systems such as Microsoft Windows, GNU/Linux or even Sun Microsystems' Solaris: never heard about Windows' hibernation or Solaris suspend and resume? I bet you have.

Apple has christened this functionality as "Safe Sleep" in its flagship OS, Mac OS/X. What's most "astonishing" about "Safe Sleep" is that you're not going to find any reference to it in your Finder menu or even in your System Preferences panes. You'll only find references to a "generic" sleep function.

Safe Sleep

During safe sleep the system will persist to disk all of the machine state (such as RAM's) so that it could be restored in the case all of the power is lost, for example during battery replacement. Under normal conditions, you'll hardly notice a resume from disk since the laptop battery power will maintain data on RAM even when the battery power has run real low. That's why during battery calibration Apple suggests to let the laptop sleep at least 5 hours. The next time you calibrate your battery, you should notice a slightly different boot screen when your laptop wakes up and reads its state from disk.

How to force a safe sleep?

Despite other implementations of a similar technology, Mac OS/X does not provide a way to force a system hibernation simply because every time your computer goes to sleep, it will persist its state to disk. This way you can let your battery discharge without worrying about your data. You could remove it, too. Next boot, it would simply read state from disk and restore it.

That's counterintuitive for who's accustomed to other OS where such a process should be explicitly triggered by the user. When using an Apple laptop, simply don't worry. You'll quickly get used to never, or very rarely, shutting down your system.

Handling your laptop while sleeping

When your laptop is sleeping, most of the hardware components will be completely off. That's the case of the hard disk: if you're laptop is equipped with a good old rotating hard drives, as soon as the computer state has been persisted, the disks will be switched off. The only evidence about this is the white led in front of your laptop: it will switch from a solid on state to a blinking state when the drives have been switched off.

Until complete disk shutdown, handle your laptop with care.

Once the laptop is sleeping, you can safely handle it as if it had been completely shut down. The real difference between a sleeping and a shut down laptop is RAM electrical state. As far as it concerns mechanical parts, there will be no difference at all. Hence:

No need to worry about hard disk heads landing on the platters. Put your sleeping laptop into your bag and safely transport it.

No need to emphasize the obvious, but I noticed a bit of misinformation about how safe sleep works and about the dos and don'ts. Indeed, safe sleep is the best way to forget about quit all applications and shut down. Reboots won't ever be faster.



Calibrating a MacBook battery

Li-ion batteries aren't exotic power sources these days: possibly, indeed, they're the most common type of battery used in consumer electronics. a Li-ion batteyr is powering your laptop (and a number of other devices) right now.

Li-ion batteries have considerably less memory effect than their predecessors and probably that's the reason why many of us don't worry that much about properly maintaining their batteries. In fact, Li-ion batteries performance degradation can be so slow that it is imperceptible for the user on a day-by-day basis, although this continuous process will typically reduce a Li-ion battery capacity by an approximate 20% per year. An consequence of this effect is a lack of accuracy on the battery charge meter some batteries provide, such as those that equip Apple notebooks.


Taking care of your battery

Ironically, Li-ion batteries do not require so big an effort to be used properly so that they can deliver their best performance to you. To say it plain: don't let electrons stagnate inside your battery and let them flow, instead. In fact, prolonged high charge periods reduce your battery life. High temperatures damage it as well. Therefore you should not be running your devices with the charger constantly plugged in, although it's a common practice for laptop users.

Ideally, you should let your battery discharge for time to time: that's why many laptop producers publish guidelines about battery usage patterns and calibration procedures. As stated, Li-ion batteries are subject to a process of reduction of their full charge capacity and, because of this process, your battery charge meter might start to lose accuracy: for example, it might display less than 100% when the battery if fully charged.

To reduce your battery wear and tear and to improve the accuracy of your battery charge meter, you should follow the instructions of your equipment to periodically calibrate the batteries of your appliances. In the case of a MacBook, as well as for most of its laptops, Apple has published calibrations instructions.

Calibrating your MacBook battery

These are the steps outlined by Apple to calibrate a MacBook Li-ion battery:
  • Plug in the power adapter and fully charge your PowerBook's battery until the light ring or LED on the power adapter plug changes to green and the onscreen meter in the menu bar indicates that the battery is fully charged.
  • Allow the battery to rest in the fully charged state for at least two hours. You may use your computer during this time as long as the adapter is plugged in.
  • Disconnect the power adapter while the computer still on and start running the computer off battery power. You may use your computer during this time. When your battery gets low, the low battery warning dialog appears on the screen.
  • At this point, save your work. Continue to use your computer; when the battery gets very low, the computer will automatically go to sleep.
  • Turn off the computer or allow it to sleep for five hours or more.
  • Connect the power adapter and leave it connected until the battery is fully charged again.

That's it. Remember to calibrate your battery from time to time depending on your usage pattern. If you use your laptop plugged in most of the time, calibrate it at least once a month.

What happens when my laptop "automatically goes to sleep"?

This may sound scaring to some of us but there's nothing to worry about. Almost every Apple laptop nowadays implement a "safe sleep" mode which if functionally very similar to Windows hibernation of Solaris' suspend and resume. Your work won't be lost because your machine state has been persisted to disk when your computer went into sleep mode. Even if your battery depletes completely (even if you replace it!), you won't lose any data and your laptop, when woken up, will restore its state from disk.