You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

WeakishReference.java 2.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant.util;
  19. import java.lang.ref.WeakReference;
  20. /**
  21. * These classes are part of some code to reduce memory leaks by only
  22. * retaining weak references to things
  23. * on Java1.2+, and yet still work (with leaky hard references) on Java1.1.
  24. * Now that Ant is 1.2+ only,
  25. * life is simpler and none of the classes are needed any more.
  26. *
  27. * They are only retained in case a third-party task uses them
  28. * @since ant1.6
  29. * @see org.apache.tools.ant.util.optional.WeakishReference12
  30. * @deprecated deprecated 1.7; will be removed in Ant1.8
  31. * Just use {@link java.lang.ref.WeakReference} directly.
  32. */
  33. public class WeakishReference {
  34. private WeakReference weakref;
  35. /**
  36. * create a new soft reference, which is bound to a
  37. * Weak reference inside
  38. *
  39. * @param reference
  40. * @see java.lang.ref.WeakReference
  41. */
  42. WeakishReference(Object reference) {
  43. this.weakref = new WeakReference(reference);
  44. }
  45. /**
  46. * Returns this reference object's referent. If this reference object has
  47. * been cleared, then this method returns <code>null</code>.
  48. *
  49. * @return The object to which this reference refers, or
  50. * <code>null</code> if this reference object has been cleared.
  51. */
  52. public Object get() {
  53. return weakref.get();
  54. }
  55. /**
  56. * create the appropriate type of reference for the java version
  57. * @param object the object that the reference will refer to.
  58. * @return reference to the Object.
  59. */
  60. public static WeakishReference createReference(Object object) {
  61. return new WeakishReference(object);
  62. }
  63. /**
  64. * This was a hard reference for Java 1.1. Since Ant1.7,
  65. * @deprecated since 1.7.
  66. * Hopefully nobody is using this.
  67. */
  68. public static class HardReference extends WeakishReference {
  69. /**
  70. * constructor.
  71. * @param object the object that the reference will refer to.
  72. */
  73. public HardReference(Object object) {
  74. super(object);
  75. }
  76. }
  77. }