简体   繁体   English

如何处置GMap实例

[英]How to dispose of a GMap instance

I have a program that use GMap. 我有一个使用GMap的程序。 The GMap is in instance X(to give exemple). GMap在实例X中(举个例子)。 Instance X is called after a login. 登录后将调用实例X。 I can logout of X and start again the login process. 我可以注销X并重新开始登录过程。 The problem is that instance X never get released. 问题是实例X永远不会释放。 I really thing that I have pinpointed the problem to the GMap, because right now I remove everything else that it loaded. 我确实已将问题定位到GMap,因为现在我删除了它加载的所有其他内容。

I tried to do this when I logout: 我注销时尝试这样做:

gmap.Manager.CancelTileCaching();
gmap.Dispose();
gmap = null;

I also remove the control itself from the xaml code with a 我还使用了

grid.Children.Remove(myMap)

Ok, Dispose does not mean, that object is removed from memory. 好的, Dispose并不意味着该对象已从内存中删除。 Dispose method just releases unmanaged resources. Dispose方法仅释放非托管资源。

.NET has managed memory. .NET具有托管内存。 And Grbage Collector (GC), that clears memory from unused objects. 还有垃圾收集器(GC),可以清除未使用的对象中的内存。

You can force GC by using method GC.Collect() . 您可以使用GC.Collect()方法强制使用GC。 But you sholdn't do it in real application. 但是您不能在实际应用中做到这一点。 Let GC do it in the most suitable moment. 让GC在最合适的时间执行此操作。

You can learn more from this video . 您可以从该视频中学到更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM