Monday, February 21, 2011

Memory Management

So I've been working on several projects involving ASP.NET 4. I've relied heavily on LINQ to talk to my SQL database. I've been curious though about how to deal with my dbml object in a code-behind C# file. For instance usually I just declare a global instance of it in my file, and reference it directly in functions that are called through out the lifetime of the page object. I didn't know if it was better to declare local instances of this object in functions instead. I posted some forum posts about this and I got an unexpected answer. Instead of using either of the above mentioned methods, I should instead use the using statement in C#.
http://msdn.microsoft.com/en-us/library/yh598w02(v=vs.80).aspx

With a 'using' statement, I can create a local instance in my function, and essentially immediately dereference it from memory as soon as my code has left the scope of my 'using'. This provides for much better memory management especially in website's with high user activity, as otherwise your server will continue to load instances of the object through your memory, and you're at the mercy of the garbage collector for when those memory allocations are destroyed.


Saturday, February 5, 2011

Duplicate iTunes So Lets Write some Code!


So once again new computer. My iTunes library is on a external hd connected as a network device. Since I don't want to actually bother mounting the network hd to my mac when I want to use iTunes I just wanted to add external music files to my local hd. An hour later, it's done, but practically every song is duplicated. I checked my network drive, and sure enough every song on it is doubled(not sure why). Regardless of reason I want to resolve this issue. Now of course I could use the 'find duplicate song' from the itunes menu, but that dones't quite solve the issue, as I still have to manually delete the duplicates. PLUS.. the songs are still duplicated on the network drive, so I'd have to do this again when I got another computer. There's a few software solutions out there that I could buy and try. But frankly I don't want to risk it messing something up. Instead why don't I make use of a perfectly good Sat night/sunday morning and script it myself. Open up terminal, g++ here we come! I'll post source code once I've finished it. I'll probably try to take a safe route. Write some recursive function, probably start at a top level directory. If there is another directory go into that. If not go through songs, if next song is duplicate of current song(account for something like a balhblah(1).mp4 ) remove it. Then terminate call. Recursion handles rest.

Blogging from android app

Google has now released an official blogger app. So far looks pretty simple and good. We'll see once I actually post this. Sorry for the lack of usefulness in this post.