Skip to content

Commit 35017b1

Browse files
committed
Added retain, and release static methods to Proxy for memory management. Now you should be retaining and releasing objects when you obtain them from Proxy.load(). They will start with a retain count of 1. Each call to retain will increment it. Releasing will decrement it, and remove from cache if 0.
1 parent b53c507 commit 35017b1

File tree

8 files changed

+127
-69
lines changed

8 files changed

+127
-69
lines changed

java/build.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
properties which you can use, check the target you are overriding in the
7171
nbproject/build-impl.xml file.
7272
73-
-->
73+
7474
<target name="-post-compile">
7575
<javah destdir="./build" force="yes" classpath="./build/classes:./lib/jna.jar">
7676
<class name="ca.weblite.objc.RuntimeUtils"/>
@@ -79,4 +79,5 @@
7979
8080
</javah>
8181
</target>
82+
-->
8283
</project>

java/nbproject/build-impl.xml

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -54,43 +54,6 @@ is divided into following sections:
5454
<property file="nbproject/project.properties"/>
5555
</target>
5656
<target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
57-
<j2seproject1:property name="platform.home" value="platforms.${platform.active}.home"/>
58-
<j2seproject1:property name="platform.bootcp" value="platforms.${platform.active}.bootclasspath"/>
59-
<j2seproject1:property name="platform.compiler" value="platforms.${platform.active}.compile"/>
60-
<j2seproject1:property name="platform.javac.tmp" value="platforms.${platform.active}.javac"/>
61-
<condition property="platform.javac" value="${platform.home}/bin/javac">
62-
<equals arg1="${platform.javac.tmp}" arg2="$${platforms.${platform.active}.javac}"/>
63-
</condition>
64-
<property name="platform.javac" value="${platform.javac.tmp}"/>
65-
<j2seproject1:property name="platform.java.tmp" value="platforms.${platform.active}.java"/>
66-
<condition property="platform.java" value="${platform.home}/bin/java">
67-
<equals arg1="${platform.java.tmp}" arg2="$${platforms.${platform.active}.java}"/>
68-
</condition>
69-
<property name="platform.java" value="${platform.java.tmp}"/>
70-
<j2seproject1:property name="platform.javadoc.tmp" value="platforms.${platform.active}.javadoc"/>
71-
<condition property="platform.javadoc" value="${platform.home}/bin/javadoc">
72-
<equals arg1="${platform.javadoc.tmp}" arg2="$${platforms.${platform.active}.javadoc}"/>
73-
</condition>
74-
<property name="platform.javadoc" value="${platform.javadoc.tmp}"/>
75-
<condition property="platform.invalid" value="true">
76-
<or>
77-
<contains string="${platform.javac}" substring="$${platforms."/>
78-
<contains string="${platform.java}" substring="$${platforms."/>
79-
<contains string="${platform.javadoc}" substring="$${platforms."/>
80-
</or>
81-
</condition>
82-
<fail unless="platform.home">Must set platform.home</fail>
83-
<fail unless="platform.bootcp">Must set platform.bootcp</fail>
84-
<fail unless="platform.java">Must set platform.java</fail>
85-
<fail unless="platform.javac">Must set platform.javac</fail>
86-
<fail if="platform.invalid">
87-
The J2SE Platform is not correctly set up.
88-
Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files.
89-
Either open the project in the IDE and setup the Platform with the same name or add it manually.
90-
For example like this:
91-
ant -Duser.properties.file=&lt;path_to_property_file&gt; jar (where you put the property "platforms.${platform.active}.home" in a .properties file)
92-
or ant -Dplatforms.${platform.active}.home=&lt;path_to_JDK_home&gt; jar (where no properties file is used)
93-
</fail>
9457
<available file="${manifest.file}" property="manifest.available"/>
9558
<condition property="splashscreen.available">
9659
<and>
@@ -225,6 +188,15 @@ is divided into following sections:
225188
<condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'">
226189
<length length="0" string="${endorsed.classpath}" when="greater"/>
227190
</condition>
191+
<condition else="false" property="jdkBug6558476">
192+
<and>
193+
<matches pattern="1\.[56]" string="${java.specification.version}"/>
194+
<not>
195+
<os family="unix"/>
196+
</not>
197+
</and>
198+
</condition>
199+
<property name="javac.fork" value="${jdkBug6558476}"/>
228200
<property name="jar.index" value="false"/>
229201
<property name="jar.index.metainf" value="${jar.index}"/>
230202
<property name="copylibs.rebase" value="true"/>
@@ -293,7 +265,7 @@ is divided into following sections:
293265
<property location="${build.dir}/empty" name="empty.dir"/>
294266
<mkdir dir="${empty.dir}"/>
295267
<mkdir dir="@{apgeneratedsrcdir}"/>
296-
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
268+
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
297269
<src>
298270
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
299271
<include name="*"/>
@@ -332,7 +304,7 @@ is divided into following sections:
332304
<sequential>
333305
<property location="${build.dir}/empty" name="empty.dir"/>
334306
<mkdir dir="${empty.dir}"/>
335-
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
307+
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
336308
<src>
337309
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
338310
<include name="*"/>
@@ -407,7 +379,7 @@ is divided into following sections:
407379
<element name="customize" optional="true"/>
408380
<sequential>
409381
<property name="junit.forkmode" value="perTest"/>
410-
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
382+
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
411383
<test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
412384
<syspropertyset>
413385
<propertyref prefix="test-sys-prop."/>
@@ -430,7 +402,7 @@ is divided into following sections:
430402
<element name="customize" optional="true"/>
431403
<sequential>
432404
<property name="junit.forkmode" value="perTest"/>
433-
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
405+
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
434406
<batchtest todir="${build.test.results.dir}">
435407
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
436408
<filename name="@{testincludes}"/>
@@ -466,7 +438,7 @@ is divided into following sections:
466438
</fileset>
467439
</union>
468440
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
469-
<testng classfilesetref="test.set" failureProperty="tests.failed" jvm="${platform.java}" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="ObjCBridge" testname="TestNG tests" workingDir="${work.dir}">
441+
<testng classfilesetref="test.set" failureProperty="tests.failed" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="ObjCBridge" testname="TestNG tests" workingDir="${work.dir}">
470442
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
471443
<propertyset>
472444
<propertyref prefix="test-sys-prop."/>
@@ -546,7 +518,7 @@ is divided into following sections:
546518
<element name="customize" optional="true"/>
547519
<sequential>
548520
<property name="junit.forkmode" value="perTest"/>
549-
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
521+
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
550522
<test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
551523
<syspropertyset>
552524
<propertyref prefix="test-sys-prop."/>
@@ -571,7 +543,7 @@ is divided into following sections:
571543
<element name="customize" optional="true"/>
572544
<sequential>
573545
<property name="junit.forkmode" value="perTest"/>
574-
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
546+
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
575547
<batchtest todir="${build.test.results.dir}">
576548
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
577549
<filename name="@{testincludes}"/>
@@ -748,9 +720,6 @@ is divided into following sections:
748720
<classpath>
749721
<path path="@{classpath}"/>
750722
</classpath>
751-
<bootclasspath>
752-
<path path="${platform.bootcp}"/>
753-
</bootclasspath>
754723
</nbjpdastart>
755724
</sequential>
756725
</macrodef>
@@ -766,9 +735,7 @@ is divided into following sections:
766735
</macrodef>
767736
</target>
768737
<target name="-init-debug-args">
769-
<exec executable="${platform.java}" outputproperty="version-output">
770-
<arg value="-version"/>
771-
</exec>
738+
<property name="version-output" value="java version &quot;${ant.java.version}"/>
772739
<condition property="have-jdk-older-than-1.4">
773740
<or>
774741
<contains string="${version-output}" substring="java version &quot;1.0"/>
@@ -793,7 +760,7 @@ is divided into following sections:
793760
<attribute default="${debug.classpath}" name="classpath"/>
794761
<element name="customize" optional="true"/>
795762
<sequential>
796-
<java classname="@{classname}" dir="${work.dir}" fork="true" jvm="${platform.java}">
763+
<java classname="@{classname}" dir="${work.dir}" fork="true">
797764
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
798765
<jvmarg line="${debug-args-line}"/>
799766
<jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
@@ -820,7 +787,7 @@ is divided into following sections:
820787
<attribute default="jvm" name="jvm"/>
821788
<element name="customize" optional="true"/>
822789
<sequential>
823-
<java classname="@{classname}" dir="${work.dir}" fork="true" jvm="${platform.java}">
790+
<java classname="@{classname}" dir="${work.dir}" fork="true">
824791
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
825792
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
826793
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
@@ -1007,7 +974,7 @@ is divided into following sections:
1007974
<path path="${run.classpath}"/>
1008975
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
1009976
</pathconvert>
1010-
<echo level="info">${platform.java} -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
977+
<echo level="info">java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
1011978
</target>
1012979
<target depends="init" if="do.archive" name="-do-jar-with-libraries-create-manifest" unless="manifest.available">
1013980
<tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
@@ -1034,7 +1001,7 @@ is divided into following sections:
10341001
<j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
10351002
<echo level="info">To run this application from the command line without Ant, try:</echo>
10361003
<property location="${dist.jar}" name="dist.jar.resolved"/>
1037-
<echo level="info">${platform.java} -jar "${dist.jar.resolved}"</echo>
1004+
<echo level="info">java -jar "${dist.jar.resolved}"</echo>
10381005
</target>
10391006
<target depends="-do-jar-with-libraries-pack" if="do.archive" name="-do-jar-with-libraries-delete-manifest">
10401007
<delete>
@@ -1225,7 +1192,7 @@ is divided into following sections:
12251192
</not>
12261193
</and>
12271194
</condition>
1228-
<javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" executable="${platform.javadoc}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
1195+
<javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
12291196
<classpath>
12301197
<path path="${javac.classpath}"/>
12311198
</classpath>

java/nbproject/genfiles.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ build.xml.script.CRC32=0f76d9ac
33
build.xml.stylesheet.CRC32=[email protected]
44
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
55
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6-
nbproject/build-impl.xml.data.CRC32=5766330d
7-
nbproject/build-impl.xml.script.CRC32=7da55058
6+
nbproject/build-impl.xml.data.CRC32=bdde2110
7+
nbproject/build-impl.xml.script.CRC32=35ccd0f1
88
nbproject/build-impl.xml.stylesheet.CRC32=[email protected]

java/nbproject/project.properties

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ javac.test.classpath=\
4747
${libs.junit_4.classpath}
4848
javac.test.processorpath=\
4949
${javac.test.classpath}
50-
javadoc.additionalparam=-overview ${basedir}/src/overview.html
50+
javadoc.additionalparam=
5151
javadoc.author=false
5252
javadoc.encoding=${source.encoding}
5353
javadoc.noindex=false
@@ -69,7 +69,7 @@ jnlp.signing.alias=
6969
jnlp.signing.keystore=
7070
meta.inf.dir=${src.dir}/META-INF
7171
mkdist.disabled=true
72-
platform.active=JDK_1.7
72+
platform.active=default_platform
7373
run.classpath=\
7474
${javac.classpath}:\
7575
${build.classes.dir}
@@ -79,7 +79,8 @@ run.classpath=\
7979
run.jvmargs=
8080
run.test.classpath=\
8181
${javac.test.classpath}:\
82-
${build.test.classes.dir}
82+
${build.test.classes.dir}:\
83+
${libs.junit_4.classpath}
8384
source.encoding=UTF-8
8485
src.dir=src
8586
test.src.dir=test

java/nbproject/project.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<configuration>
55
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
66
<name>ObjCBridge</name>
7-
<explicit-platform explicit-source-supported="true"/>
87
<source-roots>
98
<root id="src.dir"/>
109
</source-roots>

java/src/ca/weblite/objc/NSObject.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ public void forwardInvocation(long linvocation) {
486486
try {
487487

488488
Object res = method.invoke(this, args);
489+
490+
// We should release the arguments now since we retained them before
491+
// to prevent memory leaks.
492+
for ( int i=0; i<args.length; i++){
493+
Proxy.release(args[i]);
494+
}
495+
489496
long returnType = (long)pSig.send("methodReturnType");
490497

491498
String strReturnType = new Pointer(returnType).getString(0);

0 commit comments

Comments
 (0)