468,740 Members | 2,073 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,740 developers. It's quick & easy.

App don't stop when closing the form

Hi,
My app does not stop whan I click on the form. I mean, the form is
closing, but the process keeps running in the task manager. So I figured
there are memory leaks or some object's process stuck at some point. Is
there an easy way to know where it comes from other than putting breakpoints
all over the code? 'cause it's huge and I would have to set breakpoints for
at least a day or two

thanks
Jul 21 '05 #1
16 1671
Obviously you have wrong approach on creating and destroying objects
instances.
For all objects that have implemented IDisposable, i suggest you to call
obj.Dispose and set it to obj = Nothing (or null) when you dont need him any
more.

.... it is also possible that you did not exit some loop !?

Regards,
Josip Habjan
URL: http://www.habjansoftware.com


"ThunderMusic" <NO*******@sympatico.caSPAMATALL> wrote in message
news:OS*************@TK2MSFTNGP12.phx.gbl...
Hi,
My app does not stop whan I click on the form. I mean, the form is
closing, but the process keeps running in the task manager. So I figured
there are memory leaks or some object's process stuck at some point. Is
there an easy way to know where it comes from other than putting
breakpoints
all over the code? 'cause it's huge and I would have to set breakpoints
for
at least a day or two

thanks

Jul 21 '05 #2
ThunderMusic,

What do you mean with keeps running, all day long or a short time?

Cor
Jul 21 '05 #3
Josip,
For all objects that have implemented IDisposable, i suggest you to call
obj.Dispose and set it to obj = Nothing (or null) when you dont need him
any more.


All textboxes, panels, forms, comboboxes and other controls and datasets
etc, which are on the forms, which have IDisposable implemented?

Cor
Jul 21 '05 #4
no .. you misunderstand me.. or i explaned wrong....

see:
http://gotdotnet.com/team/libraries/...anagement.aspx

Regards,
Josip Habjan
URL: http://www.habjansoftware.com


"Cor Ligthert" <no************@planet.nl> wrote in message
news:e%****************@TK2MSFTNGP14.phx.gbl...
Josip,
For all objects that have implemented IDisposable, i suggest you to call
obj.Dispose and set it to obj = Nothing (or null) when you dont need him
any more.


All textboxes, panels, forms, comboboxes and other controls and datasets
etc, which are on the forms, which have IDisposable implemented?

Cor

Jul 21 '05 #5
And also:
#1: http://weblogs.asp.net/pwilson/archi.../20/77435.aspx
#2:
http://msdn.microsoft.com/library/de...sposeTopic.asp
#3: http://www.codeproject.com/dotnet/GC_101.asp
.... etc...

Regards,
Josip Habjan
URL: http://www.habjansoftware.com

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e%****************@TK2MSFTNGP14.phx.gbl...
Josip,
For all objects that have implemented IDisposable, i suggest you to call
obj.Dispose and set it to obj = Nothing (or null) when you dont need him
any more.


All textboxes, panels, forms, comboboxes and other controls and datasets
etc, which are on the forms, which have IDisposable implemented?

Cor

Jul 21 '05 #6
Josip,

In your first by you supported link I did not see what you wrote, as well
not on the other from Microsoft. Adviced is that when you use unmanaged
resources to implement Idisposable.

This is already implemented in any class that inherits from component. Which
is 80% of the in my opinion in general most used. And as Jon Skeet ones has
checked 20 % of the actual ones. Disposing is mostly done in the higher
class itself. See for that the part in the hidden part of a form or a
component. This you find back in almost all samples from Microsoft about
dispose.

On the blog page there is an explanation that is for me the same as: "What
does it harm to set all integers that you have created in your procedure to
zero". If you don't understand what I want to say with that. Just leave it,
however this tells for me only something about the knowledge from the
writers of this kind of sentences.

I hope this helps,

Cor
Jul 21 '05 #7
Cor,

From my point of view, MS should keep C++ concept on creating and destroying
objects. If you create new object instance, then you are responsible to
destroy it. In framework, GC may implicate on preformances since he decides
when he will call suppressfinalize. ( I know that he is waiting for best
time, but anyway )....

I have habit to call object.dispose (and =nothing) for every object instance
that i create (except: Usercontrols, string, integer and related types).
This way, i'm shure that my application will close immediate when i close
it, and will not stay in memory for next 5 minutes (waiting for GC to do his
work) ...

Regards,
Josip Habjan
URL: http://www.habjansoftware.com

"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oh**************@TK2MSFTNGP14.phx.gbl...
Josip,

In your first by you supported link I did not see what you wrote, as well
not on the other from Microsoft. Adviced is that when you use unmanaged
resources to implement Idisposable.

This is already implemented in any class that inherits from component.
Which is 80% of the in my opinion in general most used. And as Jon Skeet
ones has checked 20 % of the actual ones. Disposing is mostly done in the
higher class itself. See for that the part in the hidden part of a form or
a component. This you find back in almost all samples from Microsoft about
dispose.

On the blog page there is an explanation that is for me the same as: "What
does it harm to set all integers that you have created in your procedure
to zero". If you don't understand what I want to say with that. Just leave
it, however this tells for me only something about the knowledge from the
writers of this kind of sentences.

I hope this helps,

Cor

Jul 21 '05 #8
Josip,

I think that we both have a different idea. I keep it by managed code.

However, that from the GC in your application is strange. My experience is
that the GC starts direct as soon as there is a kind of idle time in the
application. Even when the Graphical processor takes over the painting on
screen.

Cor
Jul 21 '05 #9
Josip Habjan <jh*****@SPAM-OFF.net.hr> wrote:
I have habit to call object.dispose (and =nothing) for every object instance
that i create (except: Usercontrols, string, integer and related types).
You can't call Dispose on most types though - there are plenty of types
which don't implement IDisposable.

Also note that setting a variable to nothing is rarely useful, IME.
This way, i'm shure that my application will close immediate when i close
it, and will not stay in memory for next 5 minutes (waiting for GC to do his
work) ...


Disposing of an object doesn't garbage collect it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #10
I mean forever... I must end the task using the task manager...

Someone told something about being stuck un a loop, I'll look into this and
look in all my always running loops.... maybe one does not stop...

thanks

"Cor Ligthert" <no************@planet.nl> a écrit dans le message de
news:%2***************@TK2MSFTNGP12.phx.gbl...
ThunderMusic,

What do you mean with keeps running, all day long or a short time?

Cor

Jul 21 '05 #11
Thundermusic,

Are you using Visual Studio Net. Than just try with setting some breakpoints
if the program is still running. It should not stop in the way you describe
it in my opinion in your debugger too.

I hope this helps,

Cor
Jul 21 '05 #12
excellent idea... thanks

"Cor Ligthert" <no************@planet.nl> a écrit dans le message de
news:u3*************@TK2MSFTNGP10.phx.gbl...
Thundermusic,

Are you using Visual Studio Net. Than just try with setting some breakpoints if the program is still running. It should not stop in the way you describe it in my opinion in your debugger too.

I hope this helps,

Cor

Jul 21 '05 #13
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Josip Habjan <jh*****@SPAM-OFF.net.hr> wrote:
I have habit to call object.dispose (and =nothing) for every object
instance
that i create (except: Usercontrols, string, integer and related types).
You can't call Dispose on most types though - there are plenty of types
which don't implement IDisposable.


I agree, but aso there are planty of types that does implements IDisposable.

Also note that setting a variable to nothing is rarely useful, IME.
May be, and may be not. Why?
Uisng FileStream .. i created new file, write something to it and then i
close it. I next step i tryed to open this same file to append something to
it, but this file was 'locked' from first step where i created it... Why?
Obviously some reference to this file is still hanginge somewhere in the
air!? I can only tell you that i tryed this fiew times and only thing that
helped is setting 'FileStream = Nothing' after I dont need it any more
(first step), and then i could reopen this same file and append something to
it. (When file was locked, restarting PC helps :o)) ...
You give me some reasonable explanation for this and then i will belive you
that setting a variable to nothing is rarely useful.
This way, i'm shure that my application will close immediate when i close
it, and will not stay in memory for next 5 minutes (waiting for GC to do
his
work) ...


Disposing of an object doesn't garbage collect it.


Yes, but as i readed somewhere GC will have less work.

Regards,
Josip Habjan
URL: http://www.habjansoftware.com
Jul 21 '05 #14
Josib,
May be, and may be not. Why?
Uisng FileStream .. i created new file, write something to it and then i
close it. I next step i tryed to open this same file to append something
to it, but this file was 'locked' from first step where i created it...
Why? Obviously some reference to this file is still hanginge somewhere in
the air!? I can only tell you that i tryed this fiew times and only thing
that helped is setting 'FileStream = Nothing' after I dont need it any
more (first step), and then i could reopen this same file and append
something to it. (When file was locked, restarting PC helps :o)) ...


Did you try this instead
http://msdn.microsoft.com/library/de...flushtopic.asp

You can also use the autoflush.

I hope this helps,

Cor
Jul 21 '05 #15
"Cor Ligthert" <no************@planet.nl> wrote in message
news:ec*************@TK2MSFTNGP15.phx.gbl...
Josib,
Did you try this instead
http://msdn.microsoft.com/library/de...flushtopic.asp

You can also use the autoflush.

I hope this helps,


hm.... as you can see 'filestream.close' will call 'filestream.flush' (you
dont need to call 'filestream.flush' if you call 'filestream.close')...
....and i always call 'filestream.close'.

Regards,
Josip Habjan
URL: http://www.habjansoftware.com
Jul 21 '05 #16
Josip Habjan <jh*****@spamoff-net.hr> wrote:
You can't call Dispose on most types though - there are plenty of types
which don't implement IDisposable.
I agree, but aso there are planty of types that does implements IDisposable.


Sure, but you said that you called Dispose on *every* object you create
except user controls, string, integer and related types.
Also note that setting a variable to nothing is rarely useful, IME.


May be, and may be not. Why?
Uisng FileStream .. i created new file, write something to it and then i
close it. I next step i tryed to open this same file to append something to
it, but this file was 'locked' from first step where i created it... Why?


I'd have to see the code, but it certainly sounds like you weren't
actually closing it properly.
Obviously some reference to this file is still hanginge somewhere in the
air!? I can only tell you that i tryed this fiew times and only thing that
helped is setting 'FileStream = Nothing' after I dont need it any more
(first step), and then i could reopen this same file and append something to
it. (When file was locked, restarting PC helps :o)) ...
You give me some reasonable explanation for this and then i will belive you
that setting a variable to nothing is rarely useful.


Under the debugger, it makes a difference in situations where you
aren't disposing properly. The correct solution is to call Dispose
appropriately.

The time it *does* make a difference is when it's a static or instance
variable, and you don't need the FileStream any more despite the rest
of the object living on. This tends to be a sign of poor design, IME.
This way, i'm shure that my application will close immediate when i close
it, and will not stay in memory for next 5 minutes (waiting for GC to do
his
work) ...


Disposing of an object doesn't garbage collect it.


Yes, but as i readed somewhere GC will have less work.


It means the finalizer doesn't need to be called, yes.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Tim Bücker | last post: by
3 posts views Thread by Saradhi | last post: by
6 posts views Thread by John S | last post: by
4 posts views Thread by SteveK | last post: by
2 posts views Thread by Bob Cummings | last post: by
16 posts views Thread by ThunderMusic | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.