Showing posts from October, 2012

When to Force Garbage Collection

I've recently been working on a C#.NET batch image resampling application. The app would take a large list of files as input, and attempt to resample all these images as fast as possible to given dimensions. This was done using only managed WPF code (no GDI), so all memory allocation and garbage collection should be left to the CLR according to recommendations.

However, the application was very quickly reaching 1.2GB plus of memory usage before starting to throw OutOfMemory exceptions. I double-checked the code, and every file being resampled appeared to be self-contained (i.e. no dangling references left around). The garbage collector was just not freeing up the memory fast enough after each re-sampling operation.

So I tested putting in a GC.Collect() at the end of each resample iteration. Memory usage of the application dropped dramatically, fluctuating between 150MB to 300MB maximum for the life-time of the application during any resample job. This eliminated the OutOfMemory ex…

Moving Windows 7 Install to New Hardware

I recently wanted to upgrade a desktop PC, which was running Windows 7 Pro x64 on an an Intel 80GB SSD, with an AMD Phenom 2 940 CPU, Gigabyte motherboard with integrated ATI graphics. The new machine was an Intel Core i7, with an Asus H77 motherboard, integrated Intel HD4000 graphics and a new 256GB Samsung SSD. The goal was to transfer Windows 7 from the old HDD to the new machine without formatting, i.e. transfer the existing Windows 7 installation as-is.

I was expecting this to be fairly difficult, and most internet forum posts tend to say that moving an installation across different hardware types is almost impossible and bound to lead to heaps of errors. However, I found a solution which is fairly easy, and worked surprisingly well!

1. First thing's first -- before doing anything else, make sure to do a full backup of your existing Windows installation onto an external hard-disk and keep it safe. You can do this using the standard "Windows Backup" utility. Make sur…

Google Blogger Broken - All stats gone

Seems like Blogger is experiencing some issues. All my stats appear to have been reset to zero in the Dashboard. Lots of similar reports on the official Google Groups here. Hopefully stats history will be restored shortly!

Update: Now fixed. All stats back to normal :-)

Windows Process Elevation and C#.NET

A Windows process inherits the permissions of the user that executes it. Most applications run fine as the currently logged in user. Some applications however need special Administrator permissions to perform certain actions (like updating machine registry settings, updating/writing to certain system locations, etc).

If you have UAC (User Access Control) enabled on a Windows Vista/7 machine (or Windows Server variants), you may have seen a prompt saying that an application requires administrator rights and asks you to confirm or deny.

As a developer, you may have developed an application that runs mostly fine under the current user, but has some feature or function that requires admin access, and so you want to know how to invoke one of these UAC elevation prompts to request temporary admin permission for your program -- you can't.

A process inherits the permissions of the user when it is first launched, and it is stuck with these permissions until terminated. So you either run yo…

Python, Django and LDAP authentication

We've recently had to integrate one of our Django web apps to an LDAP authentication server. Not having done this before, it took a little while longer than expected. There are many subtle stumbling blocks along the way. Here's a list of how we eventually got it working, and some of the issues we encountered. Let's assume your Django project is already setup and working on say a Debian based linux server. To get LDAP working, you'll need to install the following packages:

yum install openldap-clients        yum install openssl                      yum install python-ldap               django-auth-ldap  (using pip or easy_install or manually)     Make sure your apache/httpd user has read/execute permissions to the django_auth_ldap module and to all other modules and packages. Insufficient permissions can manifest in very non-descriptive error messages...
Get your LDAP server connection details. You will need: AUTH_LDAP_SERVER_URI -- the hostname of your ldap server,…