|
1 | 1 | /*
|
2 |
| - Copyright 2019 The TensorFlow Authors. All Rights Reserved. |
| 2 | +Copyright 2019 The TensorFlow Authors. All Rights Reserved. |
3 | 3 |
|
4 |
| - Licensed under the Apache License, Version 2.0 (the "License"); |
5 |
| - you may not use this file except in compliance with the License. |
6 |
| - You may obtain a copy of the License at |
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
7 | 7 |
|
8 |
| - http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 |
|
10 |
| - Unless required by applicable law or agreed to in writing, software |
11 |
| - distributed under the License is distributed on an "AS IS" BASIS, |
12 |
| - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 |
| - See the License for the specific language governing permissions and |
14 |
| - limitations under the License. |
15 |
| - ======================================================================= |
16 |
| - */ |
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +======================================================================= |
| 16 | +*/ |
17 | 17 |
|
18 | 18 | package org.tensorflow.internal.c_api;
|
19 | 19 |
|
|
25 | 25 |
|
26 | 26 | @Properties(inherit = org.tensorflow.internal.c_api.presets.tensorflow.class)
|
27 | 27 | public abstract class AbstractTF_Graph extends Pointer {
|
28 |
| - protected static class DeleteDeallocator extends TF_Graph implements Pointer.Deallocator { |
29 |
| - DeleteDeallocator(TF_Graph s) { super(s); } |
30 |
| - @Override public void deallocate() { if (!isNull()) TF_DeleteGraph(this); setNull(); } |
| 28 | + protected static class DeleteDeallocator extends TF_Graph implements Pointer.Deallocator { |
| 29 | + DeleteDeallocator(TF_Graph s) { |
| 30 | + super(s); |
31 | 31 | }
|
32 | 32 |
|
33 |
| - public AbstractTF_Graph(Pointer p) { super(p); } |
34 |
| - |
35 |
| - /** |
36 |
| - * Calls TF_NewGraph(), and registers a deallocator. |
37 |
| - * @return TF_Graph created. Do not call TF_DeleteGraph() on it. |
38 |
| - */ |
39 |
| - public static TF_Graph newGraph() { |
40 |
| - TF_Graph g = TF_NewGraph(); |
41 |
| - if (g != null) { |
42 |
| - g.deallocator(new DeleteDeallocator(g)); |
43 |
| - } |
44 |
| - return g; |
| 33 | + @Override |
| 34 | + public void deallocate() { |
| 35 | + if (!isNull()) TF_DeleteGraph(this); |
| 36 | + setNull(); |
45 | 37 | }
|
| 38 | + } |
46 | 39 |
|
47 |
| - /** |
48 |
| - * Calls the deallocator, if registered, otherwise has no effect. |
49 |
| - */ |
50 |
| - public void delete() { |
51 |
| - deallocate(); |
| 40 | + public AbstractTF_Graph(Pointer p) { |
| 41 | + super(p); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Calls TF_NewGraph(), and registers a deallocator. |
| 46 | + * |
| 47 | + * <p>Note {@link org.tensorflow.Graph} will call TF_DeleteGraph on close, so do not use this |
| 48 | + * method when constructing a reference for use inside a {@code Graph} object. |
| 49 | + * |
| 50 | + * @return TF_Graph created. Do not call TF_DeleteGraph() on it. |
| 51 | + */ |
| 52 | + public static TF_Graph newGraph() { |
| 53 | + TF_Graph g = TF_NewGraph(); |
| 54 | + if (g != null) { |
| 55 | + g.deallocator(new DeleteDeallocator(g)); |
52 | 56 | }
|
| 57 | + return g; |
| 58 | + } |
| 59 | + |
| 60 | + /** Calls the deallocator, if registered, otherwise has no effect. */ |
| 61 | + public void delete() { |
| 62 | + deallocate(); |
| 63 | + } |
53 | 64 | }
|
0 commit comments