Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
System.OutOfMemoryException and IDisposable
Message
De
19/12/2011 03:51:00
 
 
À
18/12/2011 18:39:27
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 8.0
OS:
Windows 7
Network:
Windows 2008 Server
Database:
MySQL
Divers
Thread ID:
01530931
Message ID:
01531309
Vues:
39
Hi Bonny,

Paraphrasing a snip : 'instantiating a class from within itself could certainly lead to memory issues'

I don't think that's true. At least I can't think of a normal case where it would be a problem?


>Your post is a week old, so you may have already found the answer to your question. If not, I have a question for you ... I don't totally understand what you've posted, unless you just have some errors in your posted code:
>
>You posted that this is Code in Cls1:, but then you're instantiating Cls1:
>
>object[] para = new object[] { para1, para2, para3 };
>using (Cls1 cls1 = new Cls1())
>{
>    cls1.MainProc(para);
>}
>
>
>If this is really what you meant, then you are instantiating a class from within itself and that could certainly lead to memory issues. I'm not sure what your Dispose method is actually doing, because you don't say where curProc.MaxWorkingSet comes from. You've obviously gotten it from a current process somewhere, but I have no idea where. Possibly passed in from parameters? But since you don't show that code, I'm just guessing ...
>
>The Dispose method is supposed to dispose of resources. I'm not so sure that setting curProc.MaxWorkingSet back to what it was when you first instantiated the class actually releases any resources. I know nothing about this particular property, having never used this, but IntPtr does have a .Finalize() method on it, which according to the docs is supposed to release resources.
>
>Anyway, it looks like you're messing around with some unmanaged resources and that can get tricky, from what I've heard. I don't have experience with that though. Maybe you could post some more of your code that more illustrates the problem.
>
>~~Bonnie
>
>
>
>>Hello All,
>>
>>Every day the memory consumed getting bigger and bigger and in someday System.OutOfMemoryException thrown..
>>Does it because of the class has not been disposed ?
>>
>>I am trying to implement IDisposable .. and I would appreciate if someone can give me suggestion or comment regarding on it..
>>
>>please advise..
>>
>>TIA
>>Winanjaya
>>
>>Code in Cls1
>>
>>
>>object[] para = new object[] { para1, para2, para3 };
>>using (Cls1 cls1 = new Cls1())
>>{
>>    cls1.MainProc(para);
>>}
>>
>>
>>Code class Cls1 : IDisposable
>>
>>{
>>    IntPtr _maxworkset = curProc.MaxWorkingSet;
>>    public void MainProc(object para)
>>    { 
>>      // DO SOMETHING HERE!
>>     }
>>
>>    public void Dispose() 
>>    {    
>>        GC.SuppressFinalize(this);                  
>>        curProc.MaxWorkingSet = _maxworkset;
>>    }
>>}
>>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform