It is currently Thu Mar 28, 2024 11:24 am



Reply to topic  [ 10 posts ] 
C# ASP.NET gotcha 
Author Message
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post C# ASP.NET gotcha
blah....ok, this has been biting me in the ass and I finally figured it out. Anyone going into web design with c#, be aware. #1 I figured out awhile ago, #2 I figured out today.

#1.

Data reader objects don't die on their own. So if you have a datareader object (like you would use to query a database) you have to explicitly dispose of the object and close the connection.

conn.Close();
dataReader.Dispose();

#2.

C# is SUPPOSED to automatically handle memory management. But it does a crappy job. I found that if I call pages repeatedly and rapidly, memory usage for the ASP.Net process goes up and up until my network card freaks out and I lose network connectivity.

I finally found the System.GC (garbage collector) object. One of the methods (I forget which) will echo out the memory usage. I echoed this out and, sure enough, it goes up and up. So now I manually call the garbage collector to trim out the crap.

This is BS... this shouldn't happen. The only thing I'm doing other than data reader objects (which I'm already manually killing) is setting local variables. You would think c# would be smart enough to release the memory for these as I exit the calling method. There are some objects I maintain across the entire page (like the render writer stuff) but you would think that it would be smart enough to release this memory when the page finishes rendering. I guess not.

So.... manually call the garbage collector. Blah.

I'm going to try to find more info on what the hell is really going on. I can't believe a language like c# has obvious problems like this. I mean...you'd think the asp.net render stuff would automatically to a garbage cleanup in its inherited destructor, but who knows.

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Mon Aug 13, 2007 6:08 pm
Profile WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post 
To get the number of bytes current allocated invoke:
System.GC.GetTotalMemory(false)
(true to allow current garbage collection routines to complete)

To manually start the garbage collector use:
System.GC.Collect();

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Tue Aug 14, 2007 11:51 am
Profile WWW
Duke
User avatar

Joined: Mon Mar 31, 2003 8:59 am
Posts: 1358
Location: right behind you
Reply with quote
Post 
You can't believe it? Dude, MS technology is idiotic at best. When it comes to their programming languages, it's like they were built by a bunch of retarded door knob fucking chimpanzees.


Tue Aug 14, 2007 8:43 pm
Profile YIM WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post 
Yea.... I suppose. Without the rabid anti-Microsoftism (and much of it is justified) they do alot of stuff really right. The concept of the .Net framework is great. DirectX is the only game in town worth playing (unless OpenGL gets its head out of its ass). And have you seen .Net 3.0 with Silverlight and WPF? OMFG. 3d real time graphics crap using XML, javascript and a server side language (currently .net languages obviously but I don't see why PHP wouldn't be able to do it).

If you doubt me, check this out. Warning, requires you install beta Microsoft stuff. :) But seriously, it's worth it.

http://silverlight.net/community/galler ... rt=2#vid45

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Tue Aug 14, 2007 8:59 pm
Profile WWW
Duke
User avatar

Joined: Mon Mar 31, 2003 8:59 am
Posts: 1358
Location: right behind you
Reply with quote
Post 
I'll give you that they do a few things well. The majority of things I like about working with MS technology come from 3rd parties that develop for MS despite their technology, not because of it.

What aspect of .Net do you like? I haven't seen anything in .Net that didn't strike as an ass backward solution. I also haven't worked with it as much as you.

As far as silverlight, I have seen it, and I think it is way cool. However, it is another example of why MS sucks so hard. Silverlight is cool, but it has yet to bring any needed functionality to the web. What does silverlight offer that we actually have a need for? At this point all it is going to do is create yet another (platform specific) plug in that complicates development without adding substantial value. I would be a lot less critical of silverlight is MS had already fixed IE. IE7 is leaps and bounds beyond IE6, but with so far to go why are they putting resources into this project? They are trying to compete with flash, but at this point in time all they are going to do is further fragment the market place.

/rant


Fri Aug 17, 2007 7:51 am
Profile YIM WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post 
I see your point but I respectfully disagree. :p

.Net... some things I like about .Net is the implementation of OO. It makes PHP 5's implementation look kinda lame. Not so much in the pure class functionality but in how they implement other stuff... like name spaces. The web.config file is a great idea...something you can manually create in php, of course. The App_code directory is also nice.... neat, protected little pocket accessible from anywhere else in the web app. There's also a LOT of stuff it does wrong... like arrays and database queries, though php jacks up database queries almost as bad.

Visual studio is also a really nice IDE. There're some MAJOR problems with it. Of course, I've never used an IDE for PHP so maybe I'm missing something. Notepad++ is great except for the lack of autocomplete and the VERY handy description you can get via VS.

As for silverlight.... silverlight's better than flash. Also, right now you have to download something to make silverlight work... but once .Net 3.0 comes out you probably won't. .Net 2.0 is pretty much on everyone's computer already.... I'm pretty sure 3.0 will be the same. So it should just work and not require a plugin download. As far as silverlight vs flash, flash is all 2d vector stuff, silverlight actually has 3d support (real-time 3d reflections ftw!). It's also not just a web extension, it's also stand-alone like everything else .net. You can write web apps in it, but you can also write real apps too.

Anyway, I sound likea damn fan boy now. :p I still think there's plenty to hate about MS and their products. I wish the open source community would start cranking out some nice stuff to compete.

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Sat Aug 18, 2007 8:04 pm
Profile WWW
Emperor
User avatar

Joined: Wed Apr 16, 2003 1:25 am
Posts: 2560
Reply with quote
Post 
Satis wrote:
DirectX is the only game in town worth playing (unless OpenGL gets its head out of its ass).

Oy dude, let me just mention that these two ain't that comparable as an bystander would say. An comparison would be possible between OpenGL and Direct3D. Yet, I'd draw your attention to the following: Although both OpenGL and Direct3D are basically 2D/3D graphics APIs, inside they're quite different.

With DirectX (not Direct3D only, generally), if you don't have hardware specialized to perform a particular task, you're screwed. With OpenGL (for graphics only), you may enjoy all these fancy effects without even having proper hardware. Yet, your CPU and RAM will pay the prise (which should not be making you any worries, if you have enough resources). If DirectX was not sucky about compatibility issues (PC), this wouldn't even been a suck for it, but it does. With enough resources provided, they both still can do the same job:

Yes, everything you can make on the screen with Direct3D, you can make with OpenGL as well. And vice versa. Just this fact is enough for me to call complete debate about which one is "better" futile.

Direct3D is much more widely used in computer games than OpenGL. And it has been made on that purpose by the way. On the other side, most of scientific and real-life stuff is being done in OpenGL, which is the biggest "yay" for the futility of any comparison. Each has its own purpose, although both are capable of replacing each other.

Duh, sorry for GFrEenGLisH in advance. :P

_________________
++


Tue Sep 18, 2007 3:07 pm
Profile WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post 
Actually that was very well written. I didn't have to reread any of it for grammatical reasons. :) You really are getting alot better.

Anyway, I don't know much about 3d rendering so I'll defer to you on that. I'm sure you're right. For game programming directx is it. My company writes some software that does direct 2d/3d screen painting and that's all directx based as well. OpenGL just seems to be such a small segment. But I'm no expert.

btw, on a mildly related note, the website I've been building for my company finally launched yesterday. I spent all day today fixing problems. :roll: Considering it's been in an internal 'betatest' for like 6 months, you would think people would've found these problems sometime prior to the launch.

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Thu Sep 20, 2007 3:53 pm
Profile WWW
Duke
User avatar

Joined: Mon Mar 31, 2003 8:59 am
Posts: 1358
Location: right behind you
Reply with quote
Post 
Anything we can see?


Thu Sep 20, 2007 4:12 pm
Profile YIM WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post 
yea. I'll post the link in a non-public forum.

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Fri Sep 21, 2007 1:22 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.