window: Clear the weak ref before freeing the data

This fixes a crash introduced in commit 9f2ba3d5b642973a21e7916fe1a60a5c44126720.

https://bugzilla.gnome.org/show_bug.cgi?id=706349
(cherry picked from commit ea9e71771be2afa2986d2a93d4d03fe301645456)