Extreme memory usage when `synchronized( this )` is used

Daniel Kozák via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 11 03:14:40 PDT 2015


On Mon, 11 May 2015 09:40:28 +0000
tcak via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> wrote:

> On Monday, 11 May 2015 at 09:20:50 UTC, Daniel Kozák wrote:
> >
> > On Mon, 11 May 2015 09:09:07 +0000
> > tcak via Digitalmars-d-learn 
> > <digitalmars-d-learn at puremagic.com> wrote:
> >
> >
> > I think synchronize(this) prevents GC from collect memory
> 
> I am not sure whether this is expected behaviour from 
> `synchronization` keyword.
> 
> Similar code in Java. It has settled on about 62M and didn't 
> increase at all.
> 
> [code]
> public class Main{
> 	private void other(){}
> 
> 	public void close(){
> 		synchronized( this ){
> 			other();
> 		}
> 	}
> 
> 	public void hasData(){ System.out.println("Has Data"); }
> 
> 	public static void main( String[] args ){
> 		for(long i=0; i < 250000000; ++i){
> 			Main conn = new Main();
> 
> 			conn.hasData();
> 
> 			conn.close();
> 
> 			conn = null;
> 		}
> 	}
> }
> [/code]

try destroy

void main() {
    for(long i=0; i < 250_000_000; ++i){
        auto conn = new shared Connection();
        
        conn.hasData();
        
        conn.close();
        destroy(conn);
    }
}



More information about the Digitalmars-d-learn mailing list