Changeset 4698 for pjproject


Ignore:
Timestamp:
Dec 19, 2013 3:39:30 AM (11 years ago)
Author:
nanang
Message:

Re #1716: Maintain reference to log writer to avoid crash (caused by premature cleanup by GC).

Location:
pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/jni/Android.mk

    r4697 r4698  
    88LOCAL_LDFLAGS   := $(APP_LDFLAGS) 
    99LOCAL_LDLIBS    := $(APP_LDLIBS) 
    10 LOCAL_SRC_FILES := $(PJDIR)/pjsip-apps/src/swig/java/output/pjsua2_wrap.cpp 
     10LOCAL_SRC_FILES := ../output/pjsua2_wrap.cpp 
    1111 
    1212include $(BUILD_SHARED_LIBRARY) 
  • pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MainActivity.java

    r4697 r4698  
    160160                        app.deinit(); 
    161161                        finish(); 
    162                         System.gc(); 
     162                        Runtime.getRuntime().gc(); 
    163163                        android.os.Process.killProcess(android.os.Process.myPid()); 
    164164                         
  • pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MyApp.java

    r4697 r4698  
    233233        private TransportConfig sipTpConfig = new TransportConfig(); 
    234234        private String appDir; 
     235         
     236        /* Maintain reference to log writer to avoid premature cleanup by GC */ 
     237        private MyLogWriter logWriter; 
    235238 
    236239        private final String configName = "pjsua2.json"; 
     
    270273                /* Set log config. */ 
    271274                LogConfig log_cfg = epConfig.getLogConfig(); 
    272                 log_cfg.setWriter(new MyLogWriter()); 
     275                logWriter = new MyLogWriter(); 
     276                log_cfg.setWriter(logWriter); 
    273277                log_cfg.setDecor(log_cfg.getDecor() &  
    274278                                                 ~(pj_log_decoration.PJ_LOG_HAS_CR.swigValue() |  
     
    369373                } 
    370374                 
    371                 /* Suggest to delete, as we found this causes crash when the Java 
    372                  * deletes it later after lib has been destroyed. 
     375                /* Force delete json now, as I found that Java somehow destroys it 
     376                 * after lib has been destroyed and from non-registered thread. 
    373377                 */ 
    374378                json.delete(); 
     
    415419                } catch (Exception e) {} 
    416420 
    417                 /* Suggest to delete, as we found this causes crash when the Java 
    418                  * deletes it later after lib has been destroyed. 
     421                /* Force delete json now, as I found that Java somehow destroys it 
     422                 * after lib has been destroyed and from non-registered thread. 
    419423                 */ 
    420424                json.delete(); 
     
    428432                 * deleted before lib is destroyed. 
    429433                 */ 
    430                 System.gc(); 
    431                  
     434                Runtime.getRuntime().gc(); 
     435                 
     436                /* Shutdown pjsua. Note that Endpoint destructor will also invoke 
     437                 * libDestroy(), so this will be a test of double libDestroy(). 
     438                 */ 
    432439                try { 
    433440                        ep.libDestroy(); 
    434441                } catch (Exception e) {} 
     442                 
     443                /* Force delete Endpoint here, to avoid deletion from a non- 
     444                 * registered thread (by GC?).  
     445                 */ 
     446                ep.delete(); 
    435447                ep = null; 
    436448        }  
Note: See TracChangeset for help on using the changeset viewer.