Memory management issue google maps on UITableViewCell in SWIFT 4












0














The way I have implemented is :



I have a nib : UITableViewCell, and there is google map implemented with two markers and a path between two markers.



When I run the program with sample 8 cells on UItableView, it is crashing some times, by saying app exit due to a memory management issue



In nib file "BookingHistoryTableViewCell":



import UIKit
import Google
import GoogleMaps
import GoogleMapsCore
import GooglePlaces
import GoogleToolboxForMac

class BookingHistoryTableViewCell: UITableViewCell {

//MARK: Outlets
@IBOutlet weak var bottomView: UIView!
@IBOutlet weak var mapView: GMSMapView!

override func awakeFromNib() {
super.awakeFromNib()
self.bottomView.layer.shadowColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 1).cgColor
self.bottomView.layer.shadowRadius = 3
self.bottomView.layer.shadowOpacity = 1
self.bottomView.layer.shadowOffset = CGSize(width: 0, height: 0)
}

//main gate : 6.795046, 79.900768
func setupMap(){
let lat = 6.797222
let lon = 79.902028
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: lon, zoom: 17.0)
let googleMapView = GMSMapView.map(withFrame: self.mapView.bounds, camera: camera)
// googleMapView.isMyLocationEnabled = true
// googleMapView.settings.tiltGestures = false
// googleMapView.settings.zoomGestures = false
// googleMapView.settings.scrollGestures = false
// googleMapView.accessibilityScroll(UIAccessibilityScrollDirection.left)
// googleMapView.mapStyle(withFilename: "googleMapsStyle02", andType: "json")
self.mapView.addSubview(googleMapView)
//(googleMapView, at: 0)

let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(lat, lon)
marker.title = "Main Title"
marker.snippet = "Deescription"
marker.map = googleMapView
}

override func layoutSubviews() {
super.layoutSubviews()
//self.setupMap()
}

override func layoutIfNeeded() {
super.layoutIfNeeded()
self.setupMap()
}

override func setNeedsLayout() {
super.setNeedsLayout()
// self.setupMap()
}



override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}

}


Then on tableViews at MyBookingsViewController :



viewDidLoad(){
self.tableView.register(UINib(nibName: "BookingHistoryTableViewCell" , bundle: nil), forCellReuseIdentifier: "BookingHistoryTableViewCell")
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 30
}


then as an extension I have table controls :



extension MyBookingsViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 8
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "BookingHistoryTableViewCell", for: indexPath) as! BookingHistoryTableViewCell
cell.selectionStyle = .none
return cell
}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("selected row number : (indexPath.row)")
}

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let editAction = UIContextualAction(style: .normal, title: "Edit") { (action, view, handler) in
print("tapped on Edit : (indexPath.row)")
}

let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { (action, view, handler) in
print("tapped on Delete : (indexPath.row)")
}

editAction.backgroundColor = UIColor(displayP3Red: 183/255, green: 183/255, blue: 183/255, alpha: 0.9)
editAction.image = #imageLiteral(resourceName: "icon_edit_white")
deleteAction.backgroundColor = UIColor(displayP3Red: 251/255, green: 86/255, blue: 92/255, alpha: 0.9)
deleteAction.image = #imageLiteral(resourceName: "icon_delete_white")
let configuaration = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
configuaration.performsFirstActionWithFullSwipe = true
return configuaration
}

}


This is kinda needed and in real life application there will be 100 of cells like this. is there any way to render only visible cells to the display area or some method to save the memory?










share|improve this question




















  • 1




    Need to look at your code. Show us your relevant code.
    – pkc456
    Nov 17 '18 at 18:25










  • @pkc456 please look at the code : I have edit the Question
    – Rakshitha Muranga Rodrigo
    Nov 19 '18 at 19:00






  • 1




    Why you are not calling setupMap method from awakeFromNib()?
    – pkc456
    Nov 20 '18 at 9:52










  • @pkc456 because : map layout will not fit in to the UIView, when I call it in the awakeFromNib()
    – Rakshitha Muranga Rodrigo
    Dec 3 '18 at 5:51
















0














The way I have implemented is :



I have a nib : UITableViewCell, and there is google map implemented with two markers and a path between two markers.



When I run the program with sample 8 cells on UItableView, it is crashing some times, by saying app exit due to a memory management issue



In nib file "BookingHistoryTableViewCell":



import UIKit
import Google
import GoogleMaps
import GoogleMapsCore
import GooglePlaces
import GoogleToolboxForMac

class BookingHistoryTableViewCell: UITableViewCell {

//MARK: Outlets
@IBOutlet weak var bottomView: UIView!
@IBOutlet weak var mapView: GMSMapView!

override func awakeFromNib() {
super.awakeFromNib()
self.bottomView.layer.shadowColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 1).cgColor
self.bottomView.layer.shadowRadius = 3
self.bottomView.layer.shadowOpacity = 1
self.bottomView.layer.shadowOffset = CGSize(width: 0, height: 0)
}

//main gate : 6.795046, 79.900768
func setupMap(){
let lat = 6.797222
let lon = 79.902028
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: lon, zoom: 17.0)
let googleMapView = GMSMapView.map(withFrame: self.mapView.bounds, camera: camera)
// googleMapView.isMyLocationEnabled = true
// googleMapView.settings.tiltGestures = false
// googleMapView.settings.zoomGestures = false
// googleMapView.settings.scrollGestures = false
// googleMapView.accessibilityScroll(UIAccessibilityScrollDirection.left)
// googleMapView.mapStyle(withFilename: "googleMapsStyle02", andType: "json")
self.mapView.addSubview(googleMapView)
//(googleMapView, at: 0)

let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(lat, lon)
marker.title = "Main Title"
marker.snippet = "Deescription"
marker.map = googleMapView
}

override func layoutSubviews() {
super.layoutSubviews()
//self.setupMap()
}

override func layoutIfNeeded() {
super.layoutIfNeeded()
self.setupMap()
}

override func setNeedsLayout() {
super.setNeedsLayout()
// self.setupMap()
}



override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}

}


Then on tableViews at MyBookingsViewController :



viewDidLoad(){
self.tableView.register(UINib(nibName: "BookingHistoryTableViewCell" , bundle: nil), forCellReuseIdentifier: "BookingHistoryTableViewCell")
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 30
}


then as an extension I have table controls :



extension MyBookingsViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 8
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "BookingHistoryTableViewCell", for: indexPath) as! BookingHistoryTableViewCell
cell.selectionStyle = .none
return cell
}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("selected row number : (indexPath.row)")
}

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let editAction = UIContextualAction(style: .normal, title: "Edit") { (action, view, handler) in
print("tapped on Edit : (indexPath.row)")
}

let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { (action, view, handler) in
print("tapped on Delete : (indexPath.row)")
}

editAction.backgroundColor = UIColor(displayP3Red: 183/255, green: 183/255, blue: 183/255, alpha: 0.9)
editAction.image = #imageLiteral(resourceName: "icon_edit_white")
deleteAction.backgroundColor = UIColor(displayP3Red: 251/255, green: 86/255, blue: 92/255, alpha: 0.9)
deleteAction.image = #imageLiteral(resourceName: "icon_delete_white")
let configuaration = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
configuaration.performsFirstActionWithFullSwipe = true
return configuaration
}

}


This is kinda needed and in real life application there will be 100 of cells like this. is there any way to render only visible cells to the display area or some method to save the memory?










share|improve this question




















  • 1




    Need to look at your code. Show us your relevant code.
    – pkc456
    Nov 17 '18 at 18:25










  • @pkc456 please look at the code : I have edit the Question
    – Rakshitha Muranga Rodrigo
    Nov 19 '18 at 19:00






  • 1




    Why you are not calling setupMap method from awakeFromNib()?
    – pkc456
    Nov 20 '18 at 9:52










  • @pkc456 because : map layout will not fit in to the UIView, when I call it in the awakeFromNib()
    – Rakshitha Muranga Rodrigo
    Dec 3 '18 at 5:51














0












0








0







The way I have implemented is :



I have a nib : UITableViewCell, and there is google map implemented with two markers and a path between two markers.



When I run the program with sample 8 cells on UItableView, it is crashing some times, by saying app exit due to a memory management issue



In nib file "BookingHistoryTableViewCell":



import UIKit
import Google
import GoogleMaps
import GoogleMapsCore
import GooglePlaces
import GoogleToolboxForMac

class BookingHistoryTableViewCell: UITableViewCell {

//MARK: Outlets
@IBOutlet weak var bottomView: UIView!
@IBOutlet weak var mapView: GMSMapView!

override func awakeFromNib() {
super.awakeFromNib()
self.bottomView.layer.shadowColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 1).cgColor
self.bottomView.layer.shadowRadius = 3
self.bottomView.layer.shadowOpacity = 1
self.bottomView.layer.shadowOffset = CGSize(width: 0, height: 0)
}

//main gate : 6.795046, 79.900768
func setupMap(){
let lat = 6.797222
let lon = 79.902028
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: lon, zoom: 17.0)
let googleMapView = GMSMapView.map(withFrame: self.mapView.bounds, camera: camera)
// googleMapView.isMyLocationEnabled = true
// googleMapView.settings.tiltGestures = false
// googleMapView.settings.zoomGestures = false
// googleMapView.settings.scrollGestures = false
// googleMapView.accessibilityScroll(UIAccessibilityScrollDirection.left)
// googleMapView.mapStyle(withFilename: "googleMapsStyle02", andType: "json")
self.mapView.addSubview(googleMapView)
//(googleMapView, at: 0)

let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(lat, lon)
marker.title = "Main Title"
marker.snippet = "Deescription"
marker.map = googleMapView
}

override func layoutSubviews() {
super.layoutSubviews()
//self.setupMap()
}

override func layoutIfNeeded() {
super.layoutIfNeeded()
self.setupMap()
}

override func setNeedsLayout() {
super.setNeedsLayout()
// self.setupMap()
}



override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}

}


Then on tableViews at MyBookingsViewController :



viewDidLoad(){
self.tableView.register(UINib(nibName: "BookingHistoryTableViewCell" , bundle: nil), forCellReuseIdentifier: "BookingHistoryTableViewCell")
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 30
}


then as an extension I have table controls :



extension MyBookingsViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 8
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "BookingHistoryTableViewCell", for: indexPath) as! BookingHistoryTableViewCell
cell.selectionStyle = .none
return cell
}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("selected row number : (indexPath.row)")
}

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let editAction = UIContextualAction(style: .normal, title: "Edit") { (action, view, handler) in
print("tapped on Edit : (indexPath.row)")
}

let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { (action, view, handler) in
print("tapped on Delete : (indexPath.row)")
}

editAction.backgroundColor = UIColor(displayP3Red: 183/255, green: 183/255, blue: 183/255, alpha: 0.9)
editAction.image = #imageLiteral(resourceName: "icon_edit_white")
deleteAction.backgroundColor = UIColor(displayP3Red: 251/255, green: 86/255, blue: 92/255, alpha: 0.9)
deleteAction.image = #imageLiteral(resourceName: "icon_delete_white")
let configuaration = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
configuaration.performsFirstActionWithFullSwipe = true
return configuaration
}

}


This is kinda needed and in real life application there will be 100 of cells like this. is there any way to render only visible cells to the display area or some method to save the memory?










share|improve this question















The way I have implemented is :



I have a nib : UITableViewCell, and there is google map implemented with two markers and a path between two markers.



When I run the program with sample 8 cells on UItableView, it is crashing some times, by saying app exit due to a memory management issue



In nib file "BookingHistoryTableViewCell":



import UIKit
import Google
import GoogleMaps
import GoogleMapsCore
import GooglePlaces
import GoogleToolboxForMac

class BookingHistoryTableViewCell: UITableViewCell {

//MARK: Outlets
@IBOutlet weak var bottomView: UIView!
@IBOutlet weak var mapView: GMSMapView!

override func awakeFromNib() {
super.awakeFromNib()
self.bottomView.layer.shadowColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 1).cgColor
self.bottomView.layer.shadowRadius = 3
self.bottomView.layer.shadowOpacity = 1
self.bottomView.layer.shadowOffset = CGSize(width: 0, height: 0)
}

//main gate : 6.795046, 79.900768
func setupMap(){
let lat = 6.797222
let lon = 79.902028
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: lon, zoom: 17.0)
let googleMapView = GMSMapView.map(withFrame: self.mapView.bounds, camera: camera)
// googleMapView.isMyLocationEnabled = true
// googleMapView.settings.tiltGestures = false
// googleMapView.settings.zoomGestures = false
// googleMapView.settings.scrollGestures = false
// googleMapView.accessibilityScroll(UIAccessibilityScrollDirection.left)
// googleMapView.mapStyle(withFilename: "googleMapsStyle02", andType: "json")
self.mapView.addSubview(googleMapView)
//(googleMapView, at: 0)

let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(lat, lon)
marker.title = "Main Title"
marker.snippet = "Deescription"
marker.map = googleMapView
}

override func layoutSubviews() {
super.layoutSubviews()
//self.setupMap()
}

override func layoutIfNeeded() {
super.layoutIfNeeded()
self.setupMap()
}

override func setNeedsLayout() {
super.setNeedsLayout()
// self.setupMap()
}



override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}

}


Then on tableViews at MyBookingsViewController :



viewDidLoad(){
self.tableView.register(UINib(nibName: "BookingHistoryTableViewCell" , bundle: nil), forCellReuseIdentifier: "BookingHistoryTableViewCell")
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 30
}


then as an extension I have table controls :



extension MyBookingsViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 8
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "BookingHistoryTableViewCell", for: indexPath) as! BookingHistoryTableViewCell
cell.selectionStyle = .none
return cell
}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("selected row number : (indexPath.row)")
}

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let editAction = UIContextualAction(style: .normal, title: "Edit") { (action, view, handler) in
print("tapped on Edit : (indexPath.row)")
}

let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { (action, view, handler) in
print("tapped on Delete : (indexPath.row)")
}

editAction.backgroundColor = UIColor(displayP3Red: 183/255, green: 183/255, blue: 183/255, alpha: 0.9)
editAction.image = #imageLiteral(resourceName: "icon_edit_white")
deleteAction.backgroundColor = UIColor(displayP3Red: 251/255, green: 86/255, blue: 92/255, alpha: 0.9)
deleteAction.image = #imageLiteral(resourceName: "icon_delete_white")
let configuaration = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
configuaration.performsFirstActionWithFullSwipe = true
return configuaration
}

}


This is kinda needed and in real life application there will be 100 of cells like this. is there any way to render only visible cells to the display area or some method to save the memory?







ios swift uitableview google-maps-sdk-ios






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 18:59

























asked Nov 17 '18 at 17:56









Rakshitha Muranga Rodrigo

8917




8917








  • 1




    Need to look at your code. Show us your relevant code.
    – pkc456
    Nov 17 '18 at 18:25










  • @pkc456 please look at the code : I have edit the Question
    – Rakshitha Muranga Rodrigo
    Nov 19 '18 at 19:00






  • 1




    Why you are not calling setupMap method from awakeFromNib()?
    – pkc456
    Nov 20 '18 at 9:52










  • @pkc456 because : map layout will not fit in to the UIView, when I call it in the awakeFromNib()
    – Rakshitha Muranga Rodrigo
    Dec 3 '18 at 5:51














  • 1




    Need to look at your code. Show us your relevant code.
    – pkc456
    Nov 17 '18 at 18:25










  • @pkc456 please look at the code : I have edit the Question
    – Rakshitha Muranga Rodrigo
    Nov 19 '18 at 19:00






  • 1




    Why you are not calling setupMap method from awakeFromNib()?
    – pkc456
    Nov 20 '18 at 9:52










  • @pkc456 because : map layout will not fit in to the UIView, when I call it in the awakeFromNib()
    – Rakshitha Muranga Rodrigo
    Dec 3 '18 at 5:51








1




1




Need to look at your code. Show us your relevant code.
– pkc456
Nov 17 '18 at 18:25




Need to look at your code. Show us your relevant code.
– pkc456
Nov 17 '18 at 18:25












@pkc456 please look at the code : I have edit the Question
– Rakshitha Muranga Rodrigo
Nov 19 '18 at 19:00




@pkc456 please look at the code : I have edit the Question
– Rakshitha Muranga Rodrigo
Nov 19 '18 at 19:00




1




1




Why you are not calling setupMap method from awakeFromNib()?
– pkc456
Nov 20 '18 at 9:52




Why you are not calling setupMap method from awakeFromNib()?
– pkc456
Nov 20 '18 at 9:52












@pkc456 because : map layout will not fit in to the UIView, when I call it in the awakeFromNib()
– Rakshitha Muranga Rodrigo
Dec 3 '18 at 5:51




@pkc456 because : map layout will not fit in to the UIView, when I call it in the awakeFromNib()
– Rakshitha Muranga Rodrigo
Dec 3 '18 at 5:51












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53353967%2fmemory-management-issue-google-maps-on-uitableviewcell-in-swift-4%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53353967%2fmemory-management-issue-google-maps-on-uitableviewcell-in-swift-4%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents